Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 T-SQL Error - Not a Query Error?

Author  Topic 

jp2code
Posting Yak Master

175 Posts

Posted - 2010-02-01 : 17:03:49
I've got a query I've been working with to create a windows form application that joins two tables. It runs fine, so I inserted the query's text to debug into my application to see how my values populate into my fields.

When I run my application, I get this unhelpful message:
quote:
SqlClient.SqlError Message
Incorrect syntax near 'm'.

Here is my query that runs without issue in Management Studio:

SELECT m.ID, m.[Group], m.Dept, m.Shift,
e.Firstname+' '+e.Lastname as 'Manager', m.MgrNum, m.Schedule
FROM ShiftManage m INNER JOIN Employees e ON (m.MgrNum=e.Num)

Employees::Num is a nvarchar(255) to hold a 6 digit badge number

whereas my newly created table has

ShiftManage::MgrNum is a nvarchar(10)

In some cases, the ShiftManage::MgrNum can be NULL. This indicates "no manager" - but the query in Management Studio works.

Why does Visual Studio (2008 Pro) fail?

Thanks for your time,
~Joe


Avoid Sears Home Improvement

Kristen
Test

22859 Posts

Posted - 2010-02-01 : 17:08:43
Maybe it is trying to do some parsing for you?

Long shot: but perhaps changing to

FROM ShiftManage AS m
Go to Top of Page

jp2code
Posting Yak Master

175 Posts

Posted - 2010-02-01 : 17:15:43
Nope. That didn't fix it.

I can get around it easy enough: I dropped it into a stored procedure, and it works great. Still, I'd like to know what's going on under the hood.


Avoid Sears Home Improvement
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-02-01 : 17:22:35
Might be worth running SQL Profiler and seeing what is actually being sent to SQL ... your syntax may be getting mangled somewhere along the way.
Go to Top of Page

jp2code
Posting Yak Master

175 Posts

Posted - 2010-02-01 : 17:48:15
I may have to wait until our DBA gets in tomorrow. I've got a 64-bit Windows 7 PC, and SQL 2000 won't run on it.

I've got Management Studio Express 2005 acting as my interface to the SQL 2000 server, so I don't have this feature (nor do I know what it is!).

Tomorrow, I'll try to follow this article (unless you have a better suggestion):
http://sqlservernation.com/blogs/tipweek/archive/2009/05/27/introduction-to-sql-server-profiler.aspx

Regards,
~Joe


Avoid Sears Home Improvement
Go to Top of Page
   

- Advertisement -