Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
VB
cmd.CommandText = "select MAINFILE.facno,max(fdate) as MAINTRAN.fdate ,max(fbalance) as MAINTRAN.fbalance from MAINTRAN INNER JOIN MAINFILE ON MAINFILE.facno=MAINTRAN.facno" & _
                                          "where MAINTRAN.fbankcode='" & "010" & "' and MAINTRAN.facno=MAINFILE.facno" & _
                                          "and MAINTRAN.fdate<='" & Format(prdate, "MM/dd/yyyy") & "' " & _
                                          "and MAINTRAN.fbranchcode='" & "01" & "' " & _
                                          " group by MAINFILE.facno"


With cmd
VB
dr = .ExecuteReader//error:Incorrect syntax near '.'.(sqlexception)
Posted
Updated 25-Nov-14 3:19am
v4
Comments
den2k88 25-Nov-14 9:12am    
What error?
What is the expected result?

PS: next time don't write the title all in uppercase, it means shouting and it is rude.
lakshjoshi 25-Nov-14 9:17am    
i want to display facno from mainfile and fdate&fbalance from maintran table thats it...
lakshjoshi 25-Nov-14 9:15am    
ok thank you ,my mistatke will never repeated again.here is my error
error:Incorrect syntax near '.'.(sqlexception)
i checked carefully but where this error coming from...?
Tomas Takac 25-Nov-14 9:18am    
Can you give us the value cmd.CommandText after the concatenation?
lakshjoshi 25-Nov-14 9:22am    
i am just inputing date like 25/08/2014 means it should produce values on particulars date or lees than that date...

First, do NOT use string concatenation to build SQL queries. You open yourself up to SQL Injection attacks by doing that.

Second, you're storing dates as strings. That's a huge problem because it's not culturally sensitive and sorting of dates by string value does not match the sorting of dates by actual date value.

Lastly, the casing you're using is hurting my eyes, making it difficult to read. SQL keywords are normally capitalized while column names and other identifiers are not.

Also, I don't believe you can create column aliases with a dotted notation. I'm taking about the AS clauses you have in that statement. Table aliases should be short so they don't drown out your column names thereby making your SQL easier to read.
select MAINFILE.facno,max(fdate) as MAINTRAN.fdate

should be
SELECT mf.facno, MAX(mf.fdate) AS fdate


Try your query in an SQL query tool before trying to do it in your code. You'll find it's quicker and easier to debug in the tool than it is in your code.
 
Share this answer
 
v2
Comments
lakshjoshi 25-Nov-14 9:32am    
ok...fine...
I would say your aliases are wrong. There is no reason to include the table name there:
SQL
select MAINFILE.facno, max(fdate) as MAINTRAN.fdate, ...

What you want is plain name, the same as the original column:
SQL
select MAINFILE.facno, max(fdate) as fdate, ...

Or if you want the whole string you need to use brackets like this:
SQL
select MAINFILE.facno, max(fdate) as [MAINTRAN.fdate], ...
 
Share this answer
 
Comments
lakshjoshi 25-Nov-14 9:57am    
ok
try this..

C#
cmd.CommandText = "select MAINFILE.facno,max(MAINTRAN.fdate) as MAINTRANfdate ,max(MAINTRAN.fbalance) as MAINTRANfbalance from MAINTRAN INNER JOIN MAINFILE ON MAINFILE.facno=MAINTRAN.facno" & _
                                          "where MAINTRAN.fbankcode='" & "010" & "' and MAINTRAN.facno=MAINFILE.facno" & _
                                          "and MAINTRAN.fdate<='" & Format(prdate, "MM/dd/yyyy") & "' " & _
                                          "and MAINTRAN.fbranchcode='" & "01" & "' " & _
                                          " group by MAINFILE.facno"
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900