Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 incorrect syntax near "=" and "-"

Author  Topic 

Aliresfahani
Starting Member

1 Post

Posted - 2011-03-27 : 17:43:26
I really am not good at this. i get many errors of incorrect syntax near ...


protected void Button1_Click(object sender, EventArgs e)
{
string sq1 = "with table1 as ("
+ "select * from dms_reps.[BNS\\SEsfahanizadeh].IDB_MAIN m"
+ "left join dms_reps.[BNS\\SEsfahanizadeh].IDB_Issue_Category issue"
+ " on m.Issue_Category_Prime = issue.Issue_ID"
+ "),"
+ "table2 as ("
+ "select * from table1"
+ "left join dms_reps.[BNS\\SEsfahanizadeh].IDB_Product_Type"
+ "on ID = Product_ID"
+ "),"
+ "table3 as ("
+ "select * from table2 "
+ "left join dms_reps.[BNS\\SEsfahanizadeh].IDB_COMMENTS"
+ "on ID= Main_ID"
+ "),"
+ "table4 as ( "
+ "select * from table3 "
+ "left join dms_reps.[BNS\\SEsfahanizadeh].Cost_To_Bank"
+ "on Cost_Bank=Cost_ID "
+ "),"
+ "table5 as ( "
+ "select * from table4 "
+ "left join dms_reps.[BNS\\SEsfahanizadeh].IDB_Cost_Absorbed "
+ "on Cost_Absorbed=ID_Cost_Absorbed "
+ "),"
+ "table6 as ( "
+ "select * from table5 "
+ "left join dms_reps.[BNS\\SEsfahanizadeh].IDB_Origination"
+ "on Origination=ID_Origination"
+ " ),"
+ "table7 as ( "
+ "select * from table6 "
+ "left join dms_reps.[BNS\\SEsfahanizadeh].Out_Policy"
+ "on Out_policy_Prime=ID_Out_Policy"
+ "),"
+ "table8 as ( "
+ " select * from table7 "
+ "left join dms_reps.[BNS\\SEsfahanizadeh].Issue_Trigger"
+ "on Issue_Triger_Prime=ID_Triger"
+ ")"
+ " select Product_Number, DVP, Region, Issue_Category,Issue_Trigger, Out_Policy, Origination_value, Cost_To_Bank, Cost_Absorbed_values,Portofolio_Insure, No_security, Non_Compliant from table8 "

+" where Product_Number = " + productNum.Text;
//if( + productNum.Text!= null )
DataTable dt10=GenericDataAccess.ExecuteSelectCommand(sq1, "InvestigationDB");
grid.DataSource = dt10;
grid.DataBind();
}

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2011-03-27 : 18:20:19
I have couple of suggestions. First, when you concatenate using + signs, you need to insert a space at the end of the first string, or at the beginning of the second string. Your second and third lines are these:
+ "select * from dms_reps.[BNS\\SEsfahanizadeh].IDB_MAIN m"
+ "left join dms_reps.[BNS\\SEsfahanizadeh].IDB_Issue_Category issue"

That would get concatenated as
 "select * from dms_reps.[BNS\\SEsfahanizadeh].IDB_MAIN mleft join dms_reps.[BNS\\SEsfahanizadeh].IDB_Issue_Category issue"

You don't want that happening. So put a space like this:
+ "select * from dms_reps.[BNS\\SEsfahanizadeh].IDB_MAIN m  "
+ "left join dms_reps.[BNS\\SEsfahanizadeh].IDB_Issue_Category issue"

Notice the space between m and the double quotes? Do that for every line.

Second, if the above doesn't fix the problem, write your query in an SSMS window and see if you can figure out what the problem is.
Go to Top of Page
   

- Advertisement -