?
Solved

problem launching sql query from c#

Posted on 2011-09-08
3
Medium Priority
?
257 Views
Last Modified: 2012-05-12
Hi experts,
I have the following error message
If this statement is a common table expression or an xmlnamespaces clause, the previous statement must be terminated with a semicolon
when i launch a query from my c# code. The same query works on sql server.
The query is
with a as (SELECT ROW_NUMBER()  OVER (ORDER BY xxx) AS num , * from dbo.xxx) select top (200) * from a as selezione
0
Comment
Question by:dionisio_79
  • 2
3 Comments
 
LVL 5

Accepted Solution

by:
zvytas earned 1000 total points
ID: 36501185
Change the query to the following:

;
with a as (SELECT ROW_NUMBER()  OVER (ORDER BY xxx) AS num , * from dbo.xxx) select top (200) * from a as selezione

Note the semicolon at the beginning. WITH clause has to be either first statement in the batch OR you need a semicolon just before it.
0
 

Author Comment

by:dionisio_79
ID: 36501479
now I've got an incorrect sintax near ';'
incorrect sintax near ','
0
 
LVL 5

Expert Comment

by:zvytas
ID: 36501548
Show me your C# code you use to run the query.
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question