Declare @.pTable varchar(30)
DECLARE @.TotRec integer
select @.pTable = 'Salaires'
SELECT @.TotRec EXEC ('SELECT Count(*) FROM ' + @.pTable)
GO
Print @.TotRec
How can I insert the results from an EXEC command?[QUOTE][SIZE=1]Originally posted by ericjean
Declare @.pTable varchar(30)
DECLARE @.TotRec integer
select @.pTable = 'Salaires'
SELECT @.TotRec = EXEC ('SELECT Count(*) FROM ' + @.pTable)
GO
Print @.TotRec
Like that is not correct!|||Unless you are just presenting a simplified example, there is no need to use dynamic sql to get rowcounts. You can look them up directly in the system tables (sysindexes where indid in (0, 1)):
-------------
set @.TotRec =
(select sysindexes.Rowcnt
from sysobjects
inner join sysindexes on sysobjects.id = sysindexes.id
where sysobjects.name = @.pTable and sysobjects.xtype = 'U' and sysindexes.indid in (0, 1)
Print @.TotRec
-------------
blindman|||Good idea!
Thank's|||I need to do like this
Declare @.pTable varchar(30)
DECLARE @.tmp integer
select @.pTable = 'Salaires'
SELECT @.tmp = exec('SELECT count(*) FROM ' + @.pTable + ' WHERE ID = 2)|||Declare @.pTable varchar(30)
DECLARE @.tmp integer
select @.pTable = 'Salaires'
SET @.tmp = ('SELECT count(*) FROM ' + @.pTable + ' WHERE ID = 2)
@.tmp now has the count of that table
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment