Thursday, March 29, 2012
Environmental Variable
is this something that has to be done separately? If separately, which
environmental variable and how?
Thanks,
VictorHi ,
It is not at all required to set / create any environment variables before
SQL Server installation. The
installation program will do all the necessary path entries automatically.
Thanks
Hari
MCDBA
"Victor" <vmgoldberg__NO-_*SPAM*_-PLEASE@.earthlink.net> wrote in message
news:ohMvc.36767$zO3.10088@.newsread2.news.atl.earthlink.net...
> Does the setup for SQL also set the corresponding environmental variable,
or
> is this something that has to be done separately? If separately, which
> environmental variable and how?
> Thanks,
> Victor
>
Environmental Variable
is this something that has to be done separately? If separately, which
environmental variable and how?
Thanks,
Victor
Hi ,
It is not at all required to set / create any environment variables before
SQL Server installation. The
installation program will do all the necessary path entries automatically.
Thanks
Hari
MCDBA
"Victor" <vmgoldberg__NO-_*SPAM*_-PLEASE@.earthlink.net> wrote in message
news:ohMvc.36767$zO3.10088@.newsread2.news.atl.eart hlink.net...
> Does the setup for SQL also set the corresponding environmental variable,
or
> is this something that has to be done separately? If separately, which
> environmental variable and how?
> Thanks,
> Victor
>
Environment Variables
I'm trying to create a database with the parent directory being a environment variable,
something like this:
Code Snippet
CREATE DATABASE mydatabase
ON
PRIMARY(NAME = myDataBase,
FILENAME = '%PARENTDIRECTORY%\mydatabase.mdf',
the problem is I don't know to get an environment variable in transact SQL...
I know that in C# we can get it with %PARENTDIRECTORY%...
Thanx in advance
The following batch may help you...
Code Snippet
Create Table #Result
(
Data varchar(8000)
);
Insert Into #Result
Exec master..xp_cmdshell 'echo %TEMP%';
Declare @.ParentDirectory as nvarchar(256);
Select Top 1 @.ParentDirectory = Data From #result;
Select @.ParentDirectory = @.ParentDirectory + '\mydatabase.mdf'
Exec ('CREATE DATABASE mydatabase
ON
PRIMARY(NAME = myDataBase,
FILENAME = ''' + @.ParentDirectory + ''')')
Drop table #result
|||Thanx Manivannan the code above does the job, but doesn't the xp_cmdshell work only for XP users?|||
sqlclr's udf can imprement below,
This assembly's permission need to 'EXTERNAL_ACCESS'.
Usage:
Code Snippet
select dbo.GetEnvironmentVariable('temp');C# Source file:
Code Snippet
using System;using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
public partial class UserDefinedFunctions
{
[Microsoft.SqlServer.Server.SqlFunction(DataAccess=DataAccessKind.None)]
public static SqlString GetEnvironmentVariable(string variable)
{
string value = Environment.GetEnvironmentVariable(variable);
return new SqlString(value);
}
};
environment variable
hi,
can you show me how to get the value of an environment variable from a script task?
thanks!
http://msdn2.microsoft.com/en-us/library/system.environment.getenvironmentvariable.aspx|||
Public Class ScriptMain
Public Sub Main()
Dim home As String = System.Environment.GetEnvironmentVariable("HOMEDRIVE") + System.Environment.GetEnvironmentVariable("HOMEPATH")
Dts.Variables("MyDocuments").Value = Path.Combine(home, "My Documents\")
Dts.TaskResult = Dts.Results.Success
End Sub
There is a sample package that illustrates the method in action here -
Environment Variables- Raw Files
(http://wiki.sqlis.com/default.aspx/SQLISWiki/EnvironmentVariables-RawFiles.html)
Enumerating Xml elements and inserting
I have an untyped XML variable that for example holds the following data:
<Customer>
<FirstName>John</FirstName>
<Address>
<AddressLine1>1 The road</Addressline1>
<AddressLine2>Pinner</Addressline2>
<AddressLine3>London</Addressline3></Address>
<Office>
</Office><Telephone>0208123456789</Telephone>
<Address>
</Address><AddressLine1>1 The road</Addressline1>
<AddressLine2>Pinner</Addressline2>
<AddressLine3>London</Addressline3>
</Customer>
<Customer>
<FirstName>Adam</FirstName>
<Address>
<AddressLine1>19 Another road</Addressline1>
<AddressLine2>Hemel</Addressline2>
<AddressLine3>London</Addressline3></Address>
<Office>
</Office><Telephone>0208123456222</Telephone>
<Address>
</Address><AddressLine1>5 The road</Addressline1>
<AddressLine2>Hatfield</Addressline2>
<AddressLine3>London</Addressline3>
<ExternalId>2</ExternalId>
</Customer>
Using SQL DML and\or XQuery I would like to enumerate the XML elements and add an <ExternalId> element to any <Address> element if one doesn't exist with a value of NewId().
So the end result would be:
<Customer>
<FirstName>John</FirstName>
<Address>
<AddressLine1>1 The road</Addressline1>
<AddressLine2>Pinner</Addressline2>
<AddressLine3>London</Addressline3>
<ExternalId>QW34-122132WE-12334343A</ExternalId></Address>
<Office>
</Office><Telephone>0208123456789</Telephone>
<Address>
</Address><AddressLine1>1 The road</Addressline1>
<AddressLine2>Pinner</Addressline2>
<AddressLine3>London</Addressline3>
<ExternalId>QW34-122132WE-333333</ExternalId>
</Customer>
<Customer>
<FirstName>Adam</FirstName>
<Address>
<AddressLine1>19 Another road</Addressline1>
<AddressLine2>Hemel</Addressline2>
<AddressLine3>London</Addressline3>
<ExternalId>QW34-122132WE-12312312</ExternalId></Address>
<Office>
</Office><Telephone>0208123456222</Telephone>
<Address>
</Address><AddressLine1>5 The road</Addressline1>
<AddressLine2>Hatfield</Addressline2>
<AddressLine3>London</Addressline3>
<ExternalId>2</ExternalId>
</Customer>
Any help would be greatly appreciated.
Regards
Why are you using a unique identifier. Are you familiar with the performance hit that comes with using a unique identifier? I admit there are reasons to want to use a unique identifier and yours may be one of them, but frequently I see unique identifiers used without an understanding of the consequences to performance. Here are some previous threads related to this issue:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=430995&SiteID=1
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1544519&SiteID=1
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=304764&SiteID=1
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1493312&SiteID=1
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1525445&SiteID=1
|||Thanks for the reply.
Perfomance is not an issue in this instance as it will be run once in a blue moon. But thanks for the heads-up on the performance issues. It doesn't have to be NewID() it can be any globally unique number.
Regards
sql