Speaking in Code

Thursday, May 29, 2008

Misleading SQL Error

Here is the error:
Msg 245, Level 16, State 1, Procedure ApprovalWorkBenchGet, Line 10
Syntax error converting the nvarchar value 'Day' to a column of data type int.

UPDATE: The cause was a join between two disparate typed columns. For some reason I got the impression that adding these parentheses made a difference.

WRONG ANSWER
Here is the cause:
and @ApproverID is null or @ApproverID = e.EmpApproverID

Here is the solution:
and (@ApproverID is null or @ApproverID = e.EmpApproverID)

When in doubt, use parentheses.


Friday, May 23, 2008

Linked Servers

You can link to SQL Server Express 2005 databases.
One thing to remember is that you need to have SQL Server Browser running on the server you are linking to.
I've been tripped up by that twice now. But, no more.