Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Data Saving 5 56
Syntax Error 2 47
C# MVC and a global static factory that never dies 4 49
User Authentication using Digital Certificate 2 26
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

867 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

12 Experts available now in Live!

Get 1:1 Help Now