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!

Char() in the SQL error.

Status
Not open for further replies.

vbjohn

Programmer
Aug 23, 2001
67
US
This one does not work....

SET @NewPODB_NAME = 'IF EXISTS (SELECT * FROM PO0007 WHERE CODPROD = char(44) AC700MC0 char(44)) BEGIN SET @Check = 1 END'

It tells me:
Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near 'AC700MC0'

When I take out the Where clause it works.

SET @NewPODB_NAME = 'IF EXISTS (SELECT * FROM PO0007) BEGIN SET @Check = 1 END'

What am I doing wrong?
 
What is char(44)? Some kind of data type casting?

------
"There's a man... He's bald and wears a short-sleeved shirt, and somehow he's very important to me. I think his name is Homer."
(Jack O'Neill, Stargate)
[banghead]
 
It is an ASCII character.

Char(44) = '

 
I suspect this is what you want, although you may have more errors.

SET @NewPODB_NAME = 'IF EXISTS (SELECT * FROM PO0007 WHERE CODPROD = ''AC700MC0'') BEGIN SET @Check = 1 END'

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
[red]Note:[/red] That's 2 apostrophes, not a *regular* quote.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Either way I tried them both... Char(39) or Char(44). Both gave me the same error.
 
Isn't ASCII 44 a comma (,)?

------
"There's a man... He's bald and wears a short-sleeved shirt, and somehow he's very important to me. I think his name is Homer."
(Jack O'Neill, Stargate)
[banghead]
 
YEs... Char(44) is a ,

and Char(39) is what I need.
 
If you doean't want to use George's suggestion then SET must looks like this:
Code:
SET @NewPODB_NAME = 'IF EXISTS (SELECT * FROM PO0007 WHERE CODPROD = '+char(39)+'AC700MC0'+char(39)+') BEGIN SET @Check = 1 END'

Borislav Borissov
 
bborissov... Your suggestion worked. Thanks alot everyone for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top