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

Having trouble concatenating in a where clause

Status
Not open for further replies.

sk8er1

Programmer
Jan 2, 2005
229
US
I am working with a sp that contains a where clause that is concatenated like so...
Set @wherecmd = ' WHERE ' @addwhere

I need to add a piece of logic to the mix...
AND Matches.Status <> 'x'

I am having trouble with the syntax because of the apostrophes... Can someone help with this....

Thanks
 
sk8er1,
Since you did not post the original code you are working with, here is an example.

set @v_where = 'where ' + @v_status + ' = ''test'''

Hope this helps,
Regards,
--aa
 
This is what i was working with...


declare @wherecmd varchar(50)
Set @wherecmd = 'Where ' + ' matches.status <>' + '''X'''
 
If you are using the code in dynamic sql then you have two options:
1) Exec('Select * from TableA where ' + @v_fieldname + '<> ''x'''
where @v_fieldname is set to status

2) Set the value of the where clause using

declare @wherecmd varchar(50)
Set @wherecmd = ' Where ' + matches.status + ' <> ''X'''

and use exe sp_executesql (pass the whole query and output parameters as arguments) to get the columns you are looking for.

Regards,
--aa
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top