By submitting your email address, you agree to receive emails regarding relevant topic offers from TechTarget and its partners. You can withdraw your consent at any time. Contact TechTarget at 275 Grove Street, Newton, MA.
declare @strsql varchar(100) declare @tablename varchar(50) @tablename='table123' @strsql='select count(*) from ' + @tablename exec(@strsql)I am getting the output but I can't store this value in a variable for checking. I want to check like this:
/* @countvariable=0 print(@tablename)*/If there is any other solution?
declare @strsql varchar(256) create table #emptytables (tablename varchar(128), table_rowcount int) select @strsql='select distinct o.name as TableName, x.rowcnt as Table_RowCount from sysobjects o inner join sysindexes x on o.id = x.id where x.rowcnt = 0 and o.type = ''U''' insert #emptytables (TableName, Table_rowcount) exec (@strsql) select * from #emptytables drop table #emptytables
Dig Deeper on SQL Server Database Modeling and Design
Related Q&A from Joe Toscano
Getting an error when importing data from an Excel spreadsheet to SSIS in SQL Server 2005? Try lining up data types in Excel and SSIS so they match.continue reading
Is there a query to search text in a SQL Server DTS package? SQL Server expert Joe Toscano explains which database objects can be viewed.continue reading
Convert SQL Server 2000 DTS packages to SQL Server 2005 with this advice and also see how to overwrite data.continue reading
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.