Solved

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

Posted on 2008-10-17
5
1,189 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
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 …

730 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