Solved

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

Posted on 2008-10-17
5
1,185 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
  • 2
5 Comments
 
LVL 142

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 142

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:Tiggerito
Tiggerito 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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 demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

758 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now