Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am developing a report application using Visual Studio 2010 and Crystal Reports with SQL Server Express 2005. I have two tables in the database called tblUserActive with field (memberID, joindate) and tblUserInactive with field (memberID, leavedate). I want to display all the field in tblUserActive as long as not recorded in tblUserInactive. I'm using this syntax
VB
Dim mSql As String = "SELECT * FROM tblUserActive WHERE NOT memberID IN (SELECT memberID FROM tbUserInactive)"
Dim da As SqlDataAdapter = New SqlDataAdapter(mSql, mdlConnection.cn)
Dim ds As New DataSet
da.Fill(ds)

Dim rptDocument As New ReportDocument
rptDocument.Load(Application.StartupPath & "\Reports\RepMember.rpt")
rptDocument.SetDataSource(ds)

Me.CrystalReportViewer1.ReportSource = rptDocument
Me.CrystalReportViewer1.Refresh()


When I run this shows all memberID in the tblUserInactive. Is the sql syntax error? Or should I use SelectionFormula? But how can I use it while the criteria field is in another table? Please help me.
Posted

1 solution

Try by changing your SQL Suery as below.
VB
Dim mSql As String = "SELECT * FROM tblUserActive WHERE memberID NOT IN (SELECT memberID FROM tbUserInactive)"


Below link will give you more details around "Subquery".
http://msdn.microsoft.com/en-us/library/ms189575.aspx
 
Share this answer
 
Comments
derodevil 30-Sep-11 6:47am    
I use as what you suggested and it still doesn't work. Any other methods?
RaisKazi 30-Sep-11 6:54am    
Execute this query in SQL Server Query Editor, see what result you get.
derodevil 30-Sep-11 7:18am    
I have executed this syntax in SQL Server Query Editor and the result is as I'm expecting. Is it possible that Crystal Reports for VS 2010 doesn't support SQL SubQuery syntax?

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