Solved

How to continue a long query on a new line in c#.net

Posted on 2008-10-17
5
1,191 Views
Last Modified: 2012-06-27
I have a long query like this:

"select requests.id,requests.disposition,requests.staff_ID,(contacts.First_Name+' ' +contacts.Last_Name) as Contact,contacts.Office_telephone,requests.project_title,requests.create_date,text_file.text_field from requests,contacts,text_file where requests.create_date >= (SELECT CAST(CONVERT(CHAR(11),GETDATE(),113) AS datetime)) and requests.Primary_contact_ID = Contacts.ID and requests.Project_Description_Id = text_file.id order by requests.id desc";

How do i write this query onmultiple lines in C#.net?
Is there some special character that you can put after the end of each line so that  its recognized as a continuation of the query on the previous line?

Currently I have this query on one long line and I have to scroll all the way across to edit something at the end of the line
0
Comment
Question by:wademi
[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
5 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
ID: 22745589
you could do like this:
"select requests.id,requests.disposition,requests.staff_ID,(contacts.First_Name+' ' +contacts.Last_Name) as Contact "
+ " ,contacts.Office_telephone,requests.project_title,requests.create_date,text_file.text_field "
+ " from requests,contacts,text_file where requests.create_date >= (SELECT CAST(CONVERT(CHAR(11),GETDATE(),113) AS datetime)) "
+ " and requests.Primary_contact_ID = Contacts.ID and requests.Project_Description_Id = text_file.id order by requests.id desc";

Open in new window

0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 22745598
note that, actually, you should make that query into a view or a stored procedure/function, so to limit your sql in the application to just a minimum code, resp:
* exec procedure
* select * from view_name
* select * from dbo.function_name() alias
0
 
LVL 23

Assisted Solution

by:Tony McCreath
Tony McCreath earned 250 total points
ID: 22746960
Or you could use the StringBuilder class:

StringBuilder sb = new StringBuilder();
 
sb.Append("select requests.id,requests.disposition,requests.staff_ID,(contacts.First_Name+' ' +contacts.Last_Name) as Contact ");
sb.Append(" ,contacts.Office_telephone,requests.project_title,requests.create_date,text_file.text_field ");
sb.Append(" from requests,contacts,text_file where requests.create_date >= (SELECT CAST(CONVERT(CHAR(11),GETDATE(),113) AS datetime)) ");
sb.Append(" and requests.Primary_contact_ID = Contacts.ID and requests.Project_Description_Id = text_file.id order by requests.id desc");
 
return sb.ToString();

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

690 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