Solved

problem launching sql query from c#

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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Insert msdb.dbo.sysmail_event_log Process_ID into table 4 40
Selenium and Xpath 4 32
C# DataTable (in memory) vs SQL Lookups 4 36
Database Mail Profiles 1 22
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

733 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