Click here to Skip to main content
15,887,338 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
Try

......

appd = "SELECT DISTINCT TrademarkNo,ApplDate,LastRenewal,NextRenewal FROM Trademarks WHERE TrademarkNo NOT IN (0) Minus SELECT DISTINCT TRADEMARKNO,APPDATE,LASTRENEWALDATE,NEXTRENEWALDATE FROM TRADEMARK WHERE TRADEMARKNO NOT IN (0)"
            cmd1 = New OleDbCommand(appd, cn1)
            dr1 = cmd1.ExecuteReader(CommandBehavior.CloseConnection)
......

Catch ex As Exception
            MsgBox(ex.ToString)
        End Try

Is there any error in syntax of the sql query??? exception thrown on the execution of that query about syntax error....there isn't mistake in other thigs..like...datatypes of the all fields are matched...fields name are also checked..

...

In short I want to use "Minus" operator in sql query in vb.net

Posted
Updated 30-Sep-11 23:52pm
v2

Yes - take a look at http://www.java2s.com/Code/CSharp/Database-ADO.net/PassparametertoOleDbCommand.htm[^]

The sql you posted contains (0) - appropriate for string.Format - and prone to sql injection attacks.

AFAIK: Minus is not supported by MS-SQL.
It's usually a good idea to test your queries using SQL Server Management Studio ...

Best regards
Espen Harlinn
 
Share this answer
 
v2
Comments
Abhinav S 1-Oct-11 6:04am    
My 5! OP should avoid (0).
Espen Harlinn 1-Oct-11 6:06am    
Thank you, Abhinav!
Have a look at simmilar Question-Answer thread below.

http://www.sqlservercentral.com/Forums/Topic210359-9-1.aspx#bm211046
 
Share this answer
 
Comments
Abhinav S 1-Oct-11 6:04am    
Should help the OP. 5.
RaisKazi 1-Oct-11 6:05am    
Thank you Abhinav.
Espen Harlinn 1-Oct-11 6:10am    
Good point - I didn't catch the 'Minus'
RaisKazi 1-Oct-11 6:24am    
Thank you once again Espen. :)
Use the EXCEPT clause. There is no minus clause in SQL Server.
Check this[^] out.
 
Share this answer
 
Comments
Espen Harlinn 1-Oct-11 6:15am    
Right :)
Abhinav S 1-Oct-11 6:15am    
Thank you.
RaisKazi 1-Oct-11 6:17am    
My 5.
Abhinav S 1-Oct-11 6:23am    
Thanks.
NikulDarji 1-Oct-11 6:52am    
Thanx a lot all of you :)

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