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 |
Dorffius
Starting Member
36 Posts |
Posted - 2002-03-01 : 11:48:33
|
I have one recordset that returns all of the column names from a table. I want to be able to base the next recordset on the value of the fields that reside under that column name for a certain record(CSS#).The first recordset works fine using INFORMATION_SCHEMA.COLUMNS"SELECT * FROM ETATEMP WHERE Recordset2.Fields.Item("COLUMN_NAME").Value = ????????? AND CCS = '" & target & "'"Thanks in advance. |
|
rrb
SQLTeam Poet Laureate
1479 Posts |
Posted - 2002-03-20 : 17:52:49
|
I'm not sure I've quite understood, but I think this might help:It's an sp which searches ALL NVARCHAR FIELDS of a given table. Sorry I don't have time to generalise it to all field types...create procedure spSearchAllFields @sTableName nvarchar(50), @sSearchPattern nvarchar(50)as set nocount ondeclare @sSQL nvarchar(1000)--get column namescreate table #b (colname nvarchar(50),collist nvarchar(1000))insert into #bselect syscolumns.name,NULLfrom sysColumns inner join sysobjects on syscolumns.id = sysobjects.idwhere sysobjects.name = @sTableNameand syscolumns.xusertype = 231 --nvarchar only--build csv column name list where clausedeclare @sWhereClause nvarchar(1000)set @sWhereClause = ''update #bset @sWhereClause = collist = @sWhereClause + 'or ' + colname + ' like ''' + @sSearchPattern + ''' '--strip off leading 'or 'set @sWhereClause = substring(@sWhereClause, 4,len(@sWhereClause)-3)--collate SQLset @sSQL = 'select * from ' + @sTableName + ' where ' + @sWhereClauseexec (@sSQL)drop table #bgoas they say in the classics - HTH(PS I stole the idea from graz - http://www.sqlteam.com/item.asp?ItemID=765 )--I hope that when I die someone will say of me "That guy sure owed me a lot of money" |
|
|
|
|
|