Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
tranceboy_johny
Starting Member
4 Posts |
Posted - 2012-02-29 : 16:26:24
|
Hi all,Besides the fact that this is my first post on this forum, I'm also brand new to SQL stored procedure.I'll try to explain the scenario and if someone could post their advice below, it will be appreciated I need to create a stored procedure that does the following:match results of 2 queries against each other, for example, match each row returned by Query 1 with each row returned by Query 2 based on certain criteria(example, first name, last name or age). if a match is found, {do something}i will provide more information if needed |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-02-29 : 16:36:30
|
looks like a simple left join to be between queriesMake a dervied table out of them and use likeSELECT case when q2.[last name] is not null then .... else ... end,..FROM Query1 q1LEFT JOIN Query2 q2ON q2.[first name]=q1.[first name]AND q2.[last name] = q1.[last name]AND q2.age = q1.age make sure you put actual queries here------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
X002548
Not Just a Number
15586 Posts |
|
tranceboy_johny
Starting Member
4 Posts |
Posted - 2012-02-29 : 16:48:54
|
X002548The data retrieved by both queries is result of lots of inner joins/left outer joinsfor example in c#, i can use the following to find matches, don't know SQL offers something like thisforeach(Item item in list1){ if (list2.Any(x => x.firstName == item.FirstName) == true) do something....}P.S.Haah ! You're from West orange :P |
 |
|
tranceboy_johny
Starting Member
4 Posts |
Posted - 2012-02-29 : 16:52:32
|
quote: Originally posted by visakh16 looks like a simple left join to be between queriesMake a dervied table out of them and use likeSELECT case when q2.[last name] is not null then .... else ... end,..FROM Query1 q1LEFT JOIN Query2 q2ON q2.[first name]=q1.[first name]AND q2.[last name] = q1.[last name]AND q2.age = q1.age make sure you put actual queries here------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
visakh16 :Is it possible to store queries in a variable ? |
 |
|
tranceboy_johny
Starting Member
4 Posts |
Posted - 2012-02-29 : 18:35:23
|
quote: Originally posted by visakh16 looks like a simple left join to be between queriesMake a dervied table out of them and use likeSELECT case when q2.[last name] is not null then .... else ... end,..FROM Query1 q1LEFT JOIN Query2 q2ON q2.[first name]=q1.[first name]AND q2.[last name] = q1.[last name]AND q2.age = q1.age make sure you put actual queries here------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
Thanks visakh16, this helped ;) |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-02-29 : 22:34:43
|
welcome b/w you cant store query results in variable as it can hold only single valueYou can use table variables or temporary tables for that------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|