Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
SrPuma
Starting Member
1 Post |
Posted - 2013-04-12 : 17:05:33
|
The subject title might be simple but im not sure the name for this since what im trying to reach is a way to be able to see if a column has a certain value:FETCH NEXT FROM Tabs INTO @table_name, @column_nameWHILE....BEGIN Set @existing=0 SELECT @existing = count([@column_name]) FROM @table_name WHERE [@column_name]=@new so far my issue is the @column_name, which says its a invalid colum name (where i check if the @new i give exists in the records) for this purpose and the @table_name gives me the same issue, since im trying to have the cursor check for a certain table that has a FK colum name i give s PK, having this query working to open the cursor |
|
UnemployedInOz
Yak Posting Veteran
54 Posts |
Posted - 2013-04-12 : 21:14:54
|
Some thing likeCreate Table #Info (ColName varchar(max),cnt int)declare @script varchar(max)FETCH NEXT FROM Tabs INTO @table_name, @column_nameWHILE....BEGIN Set @existing=0 select @script = 'Insert Into #Info SELECT ''' + @column_name + ''',count([' + @column_name + ']) FROM ' + @table_name + ' WHERE [' + @column_name + ']= ' + @new exec (@script) |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
|
|