There is sometimes a need to figure out the maximum space that is being used by a particular column in your database. You would initially think that the LEN() function would allow you to do this, but this function does not work on Text, NText or Image data types .
So to solve this problem
SQL Server has a DATALENGTH() function.
For e.g.
SELECT name, LEN(packagedata) FROM dbo.sysdtspackages
this query will give error.
the correct query is
SELECT name, DATALENGTH(packagedata) FROM dbo.sysdtspackages
Enjoy!
Tuesday, February 27, 2007
Sunday, February 25, 2007
SQL server Identity Column information
Hi,
SQL Server 2000 has three functions that return IDENTITY information. The result of each of these three functions is dependent on three factors:
1. The session scope (which connection produced the IDENTITY value?)
2. The table scope (which table produced the IDENTITY value?)
3. The statement scope (where is the statement that produced the IDENTITY value?)
(SQL Statements that are contained in the same batch, stored procedure, or trigger are considered to be in the same scope.
So, if I call an INSERT that fires a trigger, I have two different scopes: scope 1 is inside the batch that called the INSERT, and scope 2 is inside the trigger.)
1. SELECT @@IDENTITY
This is everyone's favorite function, unchanged from earlier versions of SQL Server. It returns the last IDENTITY value produced on a connection, regardless of the table that produced the value, and regardless of the scope of the statement that produced the value.
2. SELECT IDENT_CURRENT ('tablename')
This new function returns the last IDENTITY value produced in a table, regardless of the connection that created the value, and regardless of the scope of the statement that produced the value.
3. SELECT SCOPE_IDENTITY ()
This new function returns the last IDENTITY value produced on a connection and by a statement in the same scope, regardless Of the table that produced the value.
Thank you
SQL Server 2000 has three functions that return IDENTITY information. The result of each of these three functions is dependent on three factors:
1. The session scope (which connection produced the IDENTITY value?)
2. The table scope (which table produced the IDENTITY value?)
3. The statement scope (where is the statement that produced the IDENTITY value?)
(SQL Statements that are contained in the same batch, stored procedure, or trigger are considered to be in the same scope.
So, if I call an INSERT that fires a trigger, I have two different scopes: scope 1 is inside the batch that called the INSERT, and scope 2 is inside the trigger.)
1. SELECT @@IDENTITY
This is everyone's favorite function, unchanged from earlier versions of SQL Server. It returns the last IDENTITY value produced on a connection, regardless of the table that produced the value, and regardless of the scope of the statement that produced the value.
2. SELECT IDENT_CURRENT ('tablename')
This new function returns the last IDENTITY value produced in a table, regardless of the connection that created the value, and regardless of the scope of the statement that produced the value.
3. SELECT SCOPE_IDENTITY ()
This new function returns the last IDENTITY value produced on a connection and by a statement in the same scope, regardless Of the table that produced the value.
Thank you
How to debug sql stored procedures?
Hello,
i have found a nice link for answer.
http://www.15seconds.com/issue/050106.htm
hope you will find the answer.
Thank you
i have found a nice link for answer.
http://www.15seconds.com/issue/050106.htm
hope you will find the answer.
Thank you
Thursday, February 22, 2007
Remove Noise words from Full-text indexing in SQL server
How to remove noise words from SQL server?
• Check the language of your sql using following syntax
select @@languagee.g. result : us_english
• Now here you have “English language” so…• Remove required word from following files…
1. the noise.* files under your \WINNT\System32 directory
2. noise.enu (US_English) and noise.eng (UK_English) noise word files under your SQL Server default folder of \FTDATA\SQLServer\Config.
• After making these changes and before saving the file changes, you must stop the “Microsoft Search“ service, before you can save the FTDATA noise word files. When your modifications are completed, you must run a Full Population.
Enjoy.
• Check the language of your sql using following syntax
select @@languagee.g. result : us_english
• Now here you have “English language” so…• Remove required word from following files…
1. the noise.* files under your \WINNT\System32 directory
2. noise.enu (US_English) and noise.eng (UK_English) noise word files under your SQL Server default folder of \FTDATA\SQLServer\Config.
• After making these changes and before saving the file changes, you must stop the “Microsoft Search“ service, before you can save the FTDATA noise word files. When your modifications are completed, you must run a Full Population.
Enjoy.
Function to split string in SQL
Hello
I have found one interesting function using which you can split the text with some character like ',' or any other character.
CREATE function [dbo].[Split] (@String nvarchar(4000), @Delimiter char(1))
Returns @Results Table (Items nvarchar(4000))
As
Begin
Declare @Index int
Declare @Slice nvarchar(4000)
Select @Index = 1
If @String Is NULL Return
While @Index != 0
Begin
Select @Index = CharIndex(@Delimiter, @String)
If @Index <> 0
Select @Slice = left(@String, @Index - 1)
else
Select @Slice = @String
Insert into @Results(Items) Values (@Slice)
Select @String = right(@String, Len(@String) - @Index)
If Len(@String) = 0 break
End
Return
End
Now how to use this function
select * from dbo.Split('a,b,c,d',',')
this will give following result
Items
-----
a
b
c
d
How this function can make your life easy!
Suppose if you want to insert more than one row in a table depending on above function result
you can just do as follows
insert into Table_Name (Column_Name)
select * from dbo.Split('a,b,c,d',',')
Enjoy
I have found one interesting function using which you can split the text with some character like ',' or any other character.
CREATE function [dbo].[Split] (@String nvarchar(4000), @Delimiter char(1))
Returns @Results Table (Items nvarchar(4000))
As
Begin
Declare @Index int
Declare @Slice nvarchar(4000)
Select @Index = 1
If @String Is NULL Return
While @Index != 0
Begin
Select @Index = CharIndex(@Delimiter, @String)
If @Index <> 0
Select @Slice = left(@String, @Index - 1)
else
Select @Slice = @String
Insert into @Results(Items) Values (@Slice)
Select @String = right(@String, Len(@String) - @Index)
If Len(@String) = 0 break
End
Return
End
Now how to use this function
select * from dbo.Split('a,b,c,d',',')
this will give following result
Items
-----
a
b
c
d
How this function can make your life easy!
Suppose if you want to insert more than one row in a table depending on above function result
you can just do as follows
insert into Table_Name (Column_Name)
select * from dbo.Split('a,b,c,d',',')
Enjoy
Subscribe to:
Posts (Atom)
