Below is the sql statement to get the physical path of a database.
SELECT name, filename FROM SYSFILES
--
Search This Blog
Tuesday, January 19, 2010
Wednesday, January 13, 2010
Wednesday, January 6, 2010
How to get count in a variable by running a SQL dynamic query
Below is the query to get count in a variable whether the count statement is in a dynamic query.
USE Northwind
DECLARE @tablevariable varchar(100)
SET @tablevariable = 'Categories'
DECLARE @sql nvarchar(4000), @params nvarchar(4000), @count int
SELECT @sql = N' SELECT @cnt = COUNT(*) FROM ' + quotename(@tablevariable)
SELECT @params = N'@cnt int OUTPUT'
EXEC sp_executesql @sql, @params, @cnt=@count OUTPUT
SELECT @count
Note: sp_executesql is a system defined store procedure
USE Northwind
DECLARE @tablevariable varchar(100)
SET @tablevariable = 'Categories'
DECLARE @sql nvarchar(4000), @params nvarchar(4000), @count int
SELECT @sql = N' SELECT @cnt = COUNT(*) FROM ' + quotename(@tablevariable)
SELECT @params = N'@cnt int OUTPUT'
EXEC sp_executesql @sql, @params, @cnt=@count OUTPUT
SELECT @count
Note: sp_executesql is a system defined store procedure
Subscribe to:
Posts (Atom)