Friday, 27 September 2013

How to Join to tables for each row of the other table?

How to Join to tables for each row of the other table?

I am converting some old code to get it more optimize so i stuck here i
can do it as old way by firing 2 stored procedures but i was thinking if
it is possible with the join i tried but couldn't get it right so any help
would be great
My old code and queries
dataset = Select data1,data2,data3 from table where column1='somevalue'
//now consider dataset have the records of the above query then
foreach (row in dataset)
{
Select top 1 tab2data,tab2data from table2 with (nolock) where
LtrFileName = row.data1
//Do some more functionality i can handle this part
}
so i was trying to combine these two queries by join i got it right with
left join but i can't figure out about the top 1 it gives wrong output if
apply it with the join .so basically i am asking is there a way to get
these two queries into one stored procedure and avoid all the foreach
coding part .

No comments:

Post a Comment