Declare @DBName varchar(50), @withmsg bit
Set @withmsg=1
Set @DBName='yourdatabasenmame' ---Change your databasename here
SET NOCOUNT ON
DECLARE @spidstr varchar(8000)
DECLARE @ConnKilled smallint
SET @ConnKilled=0
SET @spidstr = ''
IF db_id(@DBName) < spidstr="coalesce(@spidstr,','" dbid="db_id(@DBName)"> 0
BEGIN
EXEC(@spidstr)
SELECT @ConnKilled = COUNT(1)
FROM master..sysprocesses WHERE dbid=db_id(@DBName)
END
IF @withmsg =1
PRINT CONVERT(VARCHAR(10), @ConnKilled) + ' Connection(s) killed for DB ' + @DBName
GO
Note: Change the databasename for @DBName variable
Friday, April 2, 2010
combine rows with single column in Sql Server 2005
combine rows with single column--Query to combine multiple rows into one
DECLARE @str VARCHAR(100)
SELECT @str = COALESCE(@str + ',', '') + [ct]
FROM #cat1
Print @str
Here [ct] is column name that we have rows of data. Then finally entire rows of data is avilable in @str.
Example:
ct
--------
suresh
hemanth
kareem
malli
after processing with COALESCE then the output loks like.....
----------------------------------
suresh,hemanth,kareem,malli
DECLARE @str VARCHAR(100)
SELECT @str = COALESCE(@str + ',', '') + [ct]
FROM #cat1
Print @str
Here [ct] is column name that we have rows of data. Then finally entire rows of data is avilable in @str.
Example:
ct
--------
suresh
hemanth
kareem
malli
after processing with COALESCE then the output loks like.....
----------------------------------
suresh,hemanth,kareem,malli
Subscribe to:
Posts (Atom)