To prep my question defensively, I've utilized Google, Bing and StackOv prior to posting :-). Also, I'm new to MVC3 and still grappling with the syntactical intricacies of the framework.
I have an error in my SQL statement in the code block below which is bugging me quite a bit. The syntax appears correct. I simplified the SQL statement with a Select * From.. and it returns data just fine.
Also, if there is a better way to do this (without using an EF object), definitely open to suggestions. I really like the flexibility and control of seeing the SQL Statement - either that, or just used to it as form of habit :-).
Thanks in advance!!
@using System.Data.SqlClient;
@using System.Configuration;
@{
Layout = null;
}
@{
SqlConnection cn = null;
cn = new SqlConnection(ConfigurationManager.ConnectionStrings["sqlConn"].ToString());
cn.Open();
SqlCommand cmd = new SqlCommand((@"SELECT DISTINCT" +
"tblSBT.sname," +
"tblSBDetails.sid," +
"tblSBDetails.assignedtrack," +
"tblSBDetails.maxtrack," +
"tblSBDetails.currentvals," +
"tblSBDetails.maxvals," +
"tblSBDetails.lastupdated" +
"FROM" +
"tblSBT (NOLOCK)" +
"LEFT OUTER JOIN" +
"tblSBDetails (NOLOCK)" +
"ON" +
"tblSBT.sid = tblSBDetails.sid" +
"WHERE" +
"tblSBDetails.lastupdated > DateADD(n, -5, GETDATE())"+
"ORDER BY" +
"tblSBT.sname" +), cn);
var myreader = cmd.ExecuteReader();
}
Push and hold the shift key. While doing that, push and hold the alt key, so you have the shift and alt held down right now. Then push the up arrow to move up in the list.
Writing SQL StatementsKeywords cannot be split across lines or abbreviated. Clauses are usually placed on separate lines for readability and ease of editing.
When Oracle is not parallelizing the execution of SQL statements, each SQL statement is executed sequentially by a single process. With parallel execution, however, multiple processes work together simultaneously to execute a single SQL statement.
You can continue a long SQL*Plus command by typing a hyphen at the end of the line and pressing Return.
If you're using the @ symbol, you don't need to concatenate your strings like how you are doing it. It's also not the most efficient way of writing that piece of code when you're joining strings like that.
SqlConnection cn = null;
cn = new SqlConnection(ConfigurationManager.ConnectionStrings["sqlConn"].ToString());
cn.Open();
SqlCommand cmd = new SqlCommand((@"SELECT DISTINCT
tblSBT.sname,
tblSBDetails.sid,
tblSBT.sname,
tblSBDetails.sid,
tblSBDetails.assignedtrack,
tblSBDetails.maxtrack,
tblSBDetails.currentvals,
tblSBDetails.maxvals,
tblSBDetails.lastupdated
FROM tblSBT (NOLOCK)
LEFT OUTER JOIN tblSBDetails (NOLOCK)
ON .sid = tblSBDetails.sid
WHERE tblSBDetails.lastupdated > DateADD(n, -5, GETDATE())
ORDER BY tblSBT.sname"), cn);
var myreader = cmd.ExecuteReader();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With