Click here to Skip to main content
15,898,820 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
I am developing an application in ASP with VB.net.
In this application one user can apply for only one out of four applications. Records of these applications are placed in four tables say t1 , t2, t3, t4.

I want to search if user has already applied for any of the application or not?

All four tables are having different column Names but userID (record) will be same.

Pl help

What I have tried:

Sql = "Select FA.ApplicationID, TFA.ApplicationID, AC.ApplicationID " &
      "FROM (FreshApplications as FA  " &
      "INNER JOIN TempFreshApplications as TFA on U.UPCNo = TFA.UserID) " &
      "INNER JOIN ApplicationsForChange as AC on U.UPCNo = AC.UPCNo" &
      " where U.UPC = '" & Session("LoggedInUPCNo") & "'"
Posted
Updated 30-Aug-17 13:49pm

Try using Union All statement

See

https://docs.microsoft.com/en-us/sql/t-sql/language-elements/set-operators-union-transact-sql[^]

So you can do something like
sql = "Select sum(id) as Num from
(
Select count(userid) as id from t1 where userid = " & Session("LoggedInUPCNo") & "
union all
Select count(userid) as id from t2 where userid = " & Session("LoggedInUPCNo") & "
union all
Select count(userid) as id from t3 where userid = " & Session("LoggedInUPCNo") & "
union all
Select count(userid) as id from t4 where userid = " & Session("LoggedInUPCNo") & ") t"
 
Share this answer
 
Warning: A good practice is that you should always use parameters and not string concatenation regardless if the query is privately or publicly generated. One day, the query may be made public then it will be open to SQL Injection attacks[^] which will compromise the security of the data.
 
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