2
Answers

SQL does not return rows using variable in string

Ask a question
Here is my call using C# 
Select JobStart, JobFinalized, OrderNumber, ArrivalMileage, TotalBill as TotalJobDollars " +
                    " from Workdata where ShopAbbrev = '" + tempShopAbbrev + "' and JobStart > '" + tempStart +
                    "' and JobFinalized <= '" + tempEnd + "' and Mechanic = '" + tempEmpName + "'




here is the actual sql command


Select JobStart, JobFinalized, OrderNumber, ArrivalMileage, TotalBill as TotalJobDollars from Workdata where ShopAbbrev = 'OTWELL1' and JobStart > '7/22/2013 12:00:00 AM' and JobFinalized <= '7/27/2013 12:00:00 AM' and Mechanic = 'Anthony Otwell'


This returns 0 rows


If I assign tempEmpName the value of 'Anthony Otwell' this call works. I have never seen this before. Has anyone ever experienced this and have a resolution.


This is where I get tempEmpName 


string tempEmpName = EProductionDDL.SelectedItem.ToString();


Obviously tempEmpName is assigned the correct string as displayed in the actual sql command line ???


Ross Murray
[email protected]

Answers (2)