|
Hi,
I have two tables as following:
Table1:
AccountID Symbol Fee Price
1 AAA 10 150
1 AAA 20 250
1 BBB 30 350
2 AAA 40 450
2 CCC 50 550
3 DDD 60 650
4 EEE 70 750
6 HHH 15 250
Table2:
AccountID Symbol Share Dollar
1 AAA 100 1100
1 BBB 200 2200
2 AAA 300 3300
2 AAA 400 4400
2 CCC 500 5500
3 DDD 600 6600
4 FFF 700 7700
5 GGG 800 8800
These two tables have two common fields: AccountId and Symbol. What I want to do is to get all the data from both tables based on the same accountid and the same symbol. If one table (A) doesn't contain the account or symbol in the other table (B), just fill the column in table (A) with blanks. The result should look like:
AccountID Symbol Fee Price Share Dollar
1 AAA 10 150 100 1100
1 AAA 20 250 --- ---
1 BBB 30 350 200 2200
2 AAA 40 450 300 3300
2 AAA -- --- 400 4400
2 CCC 50 550 500 5500
3 DDD 60 650 600 6600
4 EEE 70 750 --- ----
4 FFF -- --- 700 7700
5 GGG -- --- 800 8800
6 HHH 15 250 --- ----
The columns Fee and Price in Table1 don't have relationship with the columns Share and Dollar in Table2. All I need is to display data from both table based on Account and Symbol. And I need to do it using T-SQL.
Any hint and suggestion would be appreciated.
Thanks in advance!
|
|
|
|
|
SELECT a.AccountID, a.Symbol, a.Fee, a.Price, b.AccountID, b.Symbol,
b.Share, b.Dollar
FROM tableA a
FULL OUTER JOIN tableB b IB a.AccountID = b.AccountID AND a.Symbol = b.Symbol
Regards
KP
|
|
|
|
|
Hi, Thank you for your help!
I have gotten the answer from other site:
SELECT IsNull(T1.AccountID, T2.AccountID) AS AccountID,
ISNull(T1.Symbol, T2.Symbol) AS Symbol,
T1.Fee, T1.Price, T2.Share, T2.Dollar
FROM Table1 AS T1 FULL OUTER JOIN Table2 AS T2
ON T1.AccountID = T2.AccountID AND T1.Symbol = T2.Symbol
ORDER BY AccountID, Symbol
It's basically the same as the post from jose.
|
|
|
|
|
hi,
This is the complete query to get your output.........
SELECT accountid=case when isnull(a.AccountID,'')='' then b.accountid else a.accountid end,
symbol=case when isnull(a.Symbol,'')='' then b.Symbol else a.Symbol end
, a.Fee, a.Price,
b.Share, b.Dollar
FROM tableA a
FULL outer JOIN tableB b on a.AccountID = b.AccountID AND a.Symbol = b.Symbol
order by accountid,symbol
regards
jijo jose
|
|
|
|
|
Hi,
Thank you very much! It works!
|
|
|
|
|
Hey everyone;
I would like to know if sql 2005 express edition will allow me to create web services. what i want to do is write an application that will be able to communicate to a sql database via http. i also addtional help in creating the web service, i'm new to sql 2005 and need all the help i can get.
thanks
I@n
|
|
|
|
|
Yes I believe you can create a web service in SQL Server Express. I think for the msot part Express will most everything the full version will as far as web service - could be wrong though. Check out this article:
http://davidhayden.com/blog/dave/archive/2006/03/31/2897.aspx[^]
You might also check out the code in the Teach Starter Kit[^] for Express version. Looks like there might be some code of use in it.
|
|
|
|
|
Hi
When I view a table withen DataGridView . for eg .. then rows count on the table is 5 rows .. you found at the end of rows on the dataagrid control a balck area with the back color ,,,
Can I make the DatagridView Countinue view it's rows even it is empty ..
I hope that my idea is clear
jooooo
|
|
|
|
|
Hi,
i am getting the following error while i am trying to create a table in the database in sql2005.
Unable to create table.
The transaction ended in the trigger. The batch has been aborted.
p.sethi
p.sethi
|
|
|
|
|
When exactly you are creating this table? In a trigger or something??
Gautham
|
|
|
|
|
i am not creating the table in trigger.i just enter into the database,tables,create new table.like this i am creating but while saving i am getting the error.
Unable to create table.
The transaction ended in the trigger. The batch has been aborted.
p.sethi
|
|
|
|
|
Couldnt exactly understand the cause for the problem!!
Do the formal check i.e:
Check whether you are giving the same tablename!
Any errors in the design/data of your table before saving it!
Gautham
|
|
|
|
|
Post your Syntax here and infact write all the systax here then we will be able to help you
Vuyiswa
|
|
|
|
|
I have three tables in msaccess which are related with each other using forign keys. I want to delete the row of the innertable and second table with a single query
can u help me?
My small attempt...
|
|
|
|
|
|
I need ur help for designing PAYROLL DataBase.
Any Knows Plz Send Me(US PAYROLL)>
sree reddy
|
|
|
|
|
I need ur help for designing PAYROLL DataBase.
Any body Knows Plz Send Me(US PAYROLL)
sree reddy
|
|
|
|
|
sree reddy wrote: I need ur help for designing PAYROLL DataBase
Start with the customer's requirements. What do they require the payroll database to hold? What do they require it to do?
|
|
|
|
|
hi,
Hey...how others can db design upon your requirements .....
regards
jijo jose
|
|
|
|
|
Hi
I am new to SQL ..
Curently I am trying to do database mirroring in SQL Server Management Studio Express..
After i have made a back up and restore it on another computer, there would be a Mirror choice for me to click under the tasks option after right clicking on my database .
But the Mirror choice does not appear there..
What could the problem be ?
Anyone can help me ?
Thanks in advance...
|
|
|
|
|
hi to all
My name is Devkranth .. i need help in sql.... i have 3 tables to retrieve data and display it.. there is no Primary key in any table.. but there is a common column , so if i join the tables i am getting rows duplicated... plz help me..
thanks in advance
|
|
|
|
|
hi,
you can add identity column for these tables and join with this column.
regards
jijo jose
|
|
|
|
|
hi jojo
Thanks 4 ur reply.. i will just try it and come back to u..
|
|
|
|
|
after joining all tables use one of them and put a criteria like this
--where fielname in ( select distinct fieldname from table1)--
this may solve the of duplicacy.
Pradeep Shukla
|
|
|
|
|
thanks Pradeeop
well will try it and get back soon..
|
|
|
|