Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

creating stored procedure to handle dynamic table/column lookup 1

Status
Not open for further replies.

onedunpark

IS-IT--Management
Jan 17, 2003
19
GB
Hello,

I have a (what I refer to as a) data translation table that I use to identify the target table, data column and index column for a set of updates.

Effectively, in really simple terms, I'd like to be able to pass the table name, column name and index column as parameters to an sp, which would then return an indication if it found data using something like the following logic

select @vdatacount = @vindexcolumn in @vtable
where @vindexcolumn = @vindexvalue

I've looked around but can't see how to accomplish this without explicitly specfiying the table/column names in any proposed sp.

I'm sure I must be able to do this somehow. Just perhaps can't see the wood for the trees.

Hopefully this is a simple enough explanation of the problem

Any and all suggestions greatly appreciated.

Now..back to trawling to try an find an answer myself.

Thanks

Steven
 
If you want the number of recs found
declare @sql nvarchar(8000)
declare @cnt int

select @sql = 'select @cnt = count(*) from ' + @vtable +
where ' + @vindexcolumn + ' = ''' + @vindexvalue + ''''

exec sp_executesql @sql, N'@cnt int out', @sql out

select @cnt

======================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top