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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IF (exec dynamic SQL) IS TRUE

Status
Not open for further replies.

trenttc

Technical User
Feb 25, 2002
68
US
I have a dynamic SQL statememt in a stored procedure that checks to see if a certain column name exists. I want to create an IF statement that executes the query and if the name exists (if the executed statement comes back true), execute some other code. I can't seem to get the IF THEN syntax right. Any ideas?
Example:
BEGIN
DECLARE @q VARCHAR(8);
SET @q = column name;
IF SELECT @sql = 'SELECT cname FROM sys.syscolumns
WHERE cname = @q';
EXECUTE (@sql); IS TRUE THEN
execute some code;
END IF;
END;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top