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

Problem with select statment 1

Status
Not open for further replies.

Brianfree

Programmer
Feb 6, 2008
220
GB
Hi i have the following sql query which works fine however it doesnt work in php code for mysql...

Please cab someone show me where i am going wrong...

Code:
SELECT Left(Start_Date,Len(Start_Date)-2)+'.'+Right(Start_Date,2) & IIf(End_Date Is Not Null," - " & Left(End_Date,Len(End_Date)-2)+'.'+Right(End_Date,2),"") AS Date_Range FROM vehicles

Many thanks,

Brian
 
Trouble is it's not PHP. Looks more like a mix of Basic and SQL. The SQL part needs to be wrapped into a PHP string before being executed.
 
Actually, this looks like half of it was copied out of MS Access. There are a couple of obvious problems here:

1) The IIf() function is a Microsoft thing - it doesn't exist in MySQL. The equivalent is just If().

2) Your string concatenation is all messed up. Neither & nor + will concatenate strings in MySQL. The + operator is for addition and the & operator is for bit-wise AND. You can use the CONCAT() function for string concatenation. Or, if you're running in ANSI mode, you can use the ANSI string concatenation operator, which is the double-pipe (||).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top