?
Solved

problem launching sql query from c#

Posted on 2011-09-08
3
Medium Priority
?
244 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

762 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