Click here to Skip to main content
15,040,743 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am taking over a colleagues script and having problems understanding it. What does this script do?


SQL
from Finance.dbo.vtbl_orbt sal

inner join Finance.dbo.tbl_Period_Lookup ht on ht.Current_Period = @Current_Period

where sal.SGPERI between ht.P_Minus_30 and ht.Current_Period



Usually when I do a join, I would use an inner join to join on another table instead of another number.

SQL
from Finance.dbo.vtbl_orbt sal

inner join Finance.dbo.tbl_Period_Lookup ht on ht.Current_Period = sal.SGPERI

where sal.SGPERI between ht.P_Minus_30 and @Current_Period



Is there any difference from doing it this way? if so why do people do it the previous way?



Thanks for any help on this.
Posted

In the first case, you are comaparing SGPER1 to two values within the database (i.e. ht.P_Minus_30 and ht.Current_Period).

In the second case, you are comparing the same field to a table column (i.e.P_Minus_30) and a variable @Current_Period. You can pass any value into this variable.
   
Comments
Yu Ong 13-Jan-11 20:35pm
   
Hi Abhinav, Thanks again,

However, why would someone do that since it looks confusing, why wont one just insert a column with a @current period and do teh comparison from there? Thanks.
I would be very surprised if the first example works at all.
The second example looks much better to me.
[Note] I'm at the end of a very long day, so I may just be too tired to see if something else is wrong.

Cheers.
   

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