C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Sql query need


Posted Date: 28 Aug 2008      Total Responses: 2

Posted By: kiran       Member Level: Silver     Points: 1


I have 3 tables Table1 and Table2 and Table 3 with following data
Table 1
A
1
2
3
4



Table 2
A B C
1 1 1
2 1 2
3 1 5
4 1 3

Table 3
B C D
1 2 0
1 1 0
1 3 0
1 4 0

Select all A from Table1 and Select B, C from Table2 where Table1.A=Table2.A

After this we will get some result with B and C. Finally these B and C should compare with table3 fields B and C if B and C is same then should update Table3.D to ’1’

So please tell me the correlated query for this

After the query Table 3 should look like this
Table 3
A B C
1 2 1
1 1 1
1 3 1
1 4 0

Thanks in advance
kiran




Responses

Author: Ritesh N. Jain    28 Aug 2008Member Level: GoldRating:     Points: 4
I assume the final outout should be Column B C D and not A B C as you mentioned above.

Try this Query

UPDATE Table3
SET D = (CASE D IS NOT NULL THEN 1 ELSE 0 END)
FROM Table1
INNER JOIN Table2 ON Table1.A = Table2.A
LEFT OUTER JOIN Table3 ON Table2.B = Table3.B AND Table2.C = Table3.C

GO

SELECT B,C,D
FROM Table3



Author: http://venkattechnicalblog.blogspot.com/    31 Aug 2008Member Level: DiamondRating:     Points: 2

Its confusing and am not clear about your query.

Regards,
Venkatesan Prabu. J
http://venkattechnicalblog.blogspot.com/


Post Reply
You must Sign In to post a response.
Next : indexseek
Previous : Find Nth Max value in SQL
Return to Discussion Forum
Post New Message
Category: SQL Server

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design

doors in nj

Contact Us    Privacy Policy    Terms Of Use