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

using Not Exists in dynamic sql server

Status
Not open for further replies.

rajpree

Programmer
May 24, 2005
18
0
0
US
I not sure why I am getting error with following dynamic sql :
IF @unique_identifier = 1 AND (EXISTS(SELECT * FROM table1
WHERE field_value = @field_value
AND field_id = @field_id)
OR EXISTS (SELECT * FROM table2 WHERE field_value = @field_value
AND field_id = @field_id))

SELECT @operation_result_code = 99,
@operation_message = message_desc
FROM cdosys_message
where message_code='USER_DEFINED_FIELD_UNIQUE_IDENTIFIER'

SET @select= 'ELSE IF ' + ''''+CONVERT(VARCHAR,@as_of_date,110)+''''+' IS NULL AND NOT EXISTS(SELECT TOP 1 * FROM ' + @table + ' WHERE issue_id =' +convert(varchar(10),@field_id)+')'
Exec (@select)

Error:
Server: Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'ELSE'.
Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near ')'.

any idea?
 
Before the exec (@select) to a print @select and get the exact query that's being executed. That should greatly help you out. If needed post the full query and we'll take a look at it.

Denny
MCSA (2003) / MCDBA (SQL 2000)
MCTS (SQL 2005 / Microsoft Windows SharePoint Services 3.0: Configuration / Microsoft Office SharePoint Server 2007: Configuration)
MCITP Database Administrator (SQL 2005) / Database Developer (SQL 2005)

My Blog
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top