Solved

problem launching sql query from c#

Posted on 2011-09-08
3
218 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 250 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

772 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