Showing posts with label variable. Show all posts
Showing posts with label variable. Show all posts

Friday, March 23, 2012

How to make a SELECT with a field name inside a variable?

I have a table (for example PERSONS) with several fields (NIF NAME AGE).
I have a cursors than read the differents fiels tat have this table inside a trigger fron another table that contain all the fields of the tables.
This cursor save the name of the fiels inside the variable @.FIELD.
I need to read the value of the several records of the table like:

@.FIELD='NIF' <--(CURSOR)

SELECT @.FIELS FEOM INSERTED --> select nif from inserted(persons)

This sentence doesn't works. How can I do?

Thanks, Otto Martinez.Hi,
you maye use a variable to generate the whole statement then use the exec command
Declare @.sql NVarchar(200)
set @.sql= "Select " + @.Fiels +" from inserted"
exec @.sql

Sunday, February 19, 2012

How to know if a job is running...

Howdy folks... just a quick question. Is there a system table that holds a variable that states if a job is currently running or not? Something like a status column for jobs. If so, where is it? and if not, any suggestions aside from setting a flag in a table when it runs and stops?
TIAha! Found my own answer... sp_help_job