Hi Gurus,
Can I get some help. I wanted to get the following code to return a result that using dml to include local variable both in cloumn side and table side. Sorry for the confusion. It is much easier to look at the code. Please...
JohnZ
858-5462023
johnz@missionfcu.org
Declare @tname varchar(25), @cname varchar(25)
Declare output_cursor CURSOR FOR
select tablename, columnname
from ref_sl where flag = 'Y'
Open output_cursor
Fetch Next from output_cursor INTO @tname, @cname
while @@fetch_status = 0
begin
--This is the line I want to use, but didn't work
--EXEC ('SELECT ' + @tname +', ' + @cname + ', count(' + @cname + ')' + ' FROM ' + @tname + ' group by ' + @cname)
Print 'Table Name: ' + @tname + ' Column Nmae: ' + @cname
EXEC ('SELECT COUNT(*) AS TotalCount FROM ' + @TNAME)
EXEC ('SELECT ' + @cname + ', count(' + @cname + ') as GroupCount' + ' FROM ' + @tname + ' group by ' + @cname)
fetch next from output_cursor INTO @tname, @cname
end
--select @@cursor_rows
close output_cursor
deallocate output_cursor
Can I get some help. I wanted to get the following code to return a result that using dml to include local variable both in cloumn side and table side. Sorry for the confusion. It is much easier to look at the code. Please...
JohnZ
858-5462023
johnz@missionfcu.org
Declare @tname varchar(25), @cname varchar(25)
Declare output_cursor CURSOR FOR
select tablename, columnname
from ref_sl where flag = 'Y'
Open output_cursor
Fetch Next from output_cursor INTO @tname, @cname
while @@fetch_status = 0
begin
--This is the line I want to use, but didn't work
--EXEC ('SELECT ' + @tname +', ' + @cname + ', count(' + @cname + ')' + ' FROM ' + @tname + ' group by ' + @cname)
Print 'Table Name: ' + @tname + ' Column Nmae: ' + @cname
EXEC ('SELECT COUNT(*) AS TotalCount FROM ' + @TNAME)
EXEC ('SELECT ' + @cname + ', count(' + @cname + ') as GroupCount' + ' FROM ' + @tname + ' group by ' + @cname)
fetch next from output_cursor INTO @tname, @cname
end
--select @@cursor_rows
close output_cursor
deallocate output_cursor