Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

Using Two Table
1. tbl_Cash for Cash Accounts
2. tbl_Bank for Bank Accounts

Both tables using 2 different columns having same name VoucherNo. but value is diffrent like that

For Cash VoucherNo. CB/P/201210160001
For Bank VoucherNo. BB/R/201210160001

There is a grid where column VoucherNo. should show both upper VoucherNo's Like that

ID || VocuherNo || Date || AccountName
---------------------------------------
---------------------------------------
01 CB/P/201210160001 10/15/2012 Cash
02 BB/R/201210160001 10/15/2012 Bank

How can i query in database to get VoucherNo in single column from both tables?

Please advice

Thanks,
Posted
Comments
[no name] 16-Oct-12 1:38am    
U have any primary key for the table..???
damodara naidu betha 16-Oct-12 1:40am    
Is there any relation ship between the two tables?
Afzal Shaikh 16-Oct-12 1:42am    
No , Both are different transaction tables.
Yes ,there is CompanyID in Both tables which is not unique and primary key.

A union All like shown below may help.

SQL
select VoucherNo as vNo from tbl_Cash
union all
select VoucherNo as vNo from tbl_Bank


Hope that helps, If it does mark it as answer/upvote
Thanks,
Milind
 
Share this answer
 
Comments
Afzal Shaikh 16-Oct-12 2:04am    
It works :)
Afzal Shaikh 16-Oct-12 2:08am    
order by is not working in with union all so better is solution 1
MT_ 16-Oct-12 2:09am    
No problem. what is important is that you are able to move ahead. - Milind
Solved Myself :)

SQL
SELECT VoucherNo into #A FROM tbl_Bank

Insert into #A
Select VoucherNo from tbl_Cash

Select VoucherNo from #A
 
Share this answer
 
Comments
MT_ 16-Oct-12 2:01am    
Having union as shown below will save a temporary table for 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