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

prepared statement problem 1

Status
Not open for further replies.

julen

Programmer
Mar 26, 2006
27
ES
Hi everybody!

I have a problem when i am trying to cast to a date in a prepared statement sentence.

My sql sentence part is:

|| ' WHERE '
|| ' CAST(CAST(YEAR( FH1)) AS VARCHAR(4))'
|| '-'
|| 'CAST (MONTH(FH1) AS VARCHAR(2))'
|| '-'
|| '01 AS DATE)'
|| ' >= CURRENT DATE '

And give me the error that i cannot use the - .

Any ideas to solve the problem?

Thanks.

 
The problem is that here you use syntax for the single quote that would work for an interactive SQL command. so basically the '-' needs to be placed INSIDE another container: ''-'' or "'-'".
To be honest, I do not know the solution that works with DB2. (to long ago).
In SQL server I use QUOTENAME in stored procedures , or dual single quotes:

'' '-' ''

You may need to play around and see which one works..



Ties Blom

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top