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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 IF Condition

Author  Topic 

initial_wm
Starting Member

3 Posts

Posted - 2008-12-11 : 01:08:31
Hello, I Have an Query Like :

DECLARE @MonthProcess VARCHAR(20);
DECLARE @Foreign Varchar(20);

SET @MonthProcess = '200811'
SET @Foreign = 'True'

SELECT
TR_Crew_Salary_History.Crew_ID,
M_Rank.[Rank],
TR_Crew_Data.Name,
M_Vessel.Vessel_Name,
TR_Crew_Salary_History.Fixed,
TR_Crew_Salary_History.FOT,
TR_Crew_Salary_History.Vessel_Allowance,
TR_Crew_Salary_History.Seniority_Allowance,
TR_Crew_Salary_History.Special_Allowance,
(CASE (TR_Crew_Salary_History.Currency_ID)
WHEN 'USD' THEN TR_Crew_Salary_History.Loan / (SELECT Rate FROM M_Exchange_Rate WHERE Year_Month = @MonthProcess)
ELSE TR_Crew_Salary_History.Loan END) AS Loan,
(CASE (TR_Crew_Salary_History.Currency_ID)
WHEN 'USD' THEN TR_Crew_Salary_History.HA_Amount / (SELECT Rate FROM M_Exchange_Rate WHERE Year_Month = @MonthProcess)
ELSE TR_Crew_Salary_History.HA_Amount END) AS HA_Amount,
M_Country.[Foreign]

FROM TR_Crew_Salary_History INNER JOIN
M_Rank ON TR_Crew_Salary_History.Rank_ID = M_Rank.Rank_ID INNER JOIN
TR_Crew_Data ON TR_Crew_Salary_History.Crew_ID = TR_Crew_Data.Crew_ID INNER JOIN
M_Vessel ON TR_Crew_Salary_History.Vessel_ID = M_Vessel.Vessel_ID INNER JOIN
M_Country ON TR_Crew_Data.Nationality = Country_ID

WHERE TR_Crew_Salary_History.Month_Process = @MonthProcess
AND M_Country.[Foreign] = @Foreign
ORDER BY M_Vessel.Vessel_Name, TR_Crew_Data.Crew_Id

In This Case, I Use Case... When... Then... End For The Conditional,
and now I am trying to use IF Conditional, but I get error in IF conditional...
any body can help me ?

regards

PeterNeo
Constraint Violating Yak Guru

357 Posts

Posted - 2008-12-11 : 01:30:23
First y do u want IF? it looks fine with CASE.
Is there any business rules need to be included?

"There is only one difference between a dream and an aim.
A dream requires soundless sleep to see,
whereas an aim requires sleepless efforts to achieve..!!"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-11 : 02:03:08
As per posted code, i cant see any reason why you want use if here.
Go to Top of Page

initial_wm
Starting Member

3 Posts

Posted - 2008-12-11 : 06:02:42
that's true, there's no problem in my posted code...,
but i just want to try IF Conditional in this case (my posted code),
cause I think CASE Conditional More Complicated than IF Conditional
if there's case that need more than 1 condition...,

regards
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-11 : 09:49:13
quote:
Originally posted by initial_wm

that's true, there's no problem in my posted code...,
but i just want to try IF Conditional in this case (my posted code),
cause I think CASE Conditional More Complicated than IF Conditional
if there's case that need more than 1 condition...,

regards


they are used for two different purposes. Case expression is use to conditionally select value for a field while if is used to conditionally vary resultsets.
Go to Top of Page

initial_wm
Starting Member

3 Posts

Posted - 2008-12-11 : 23:23:34
thanks for the answer, it solved my problem...

thanks for all
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-12 : 09:36:51
welcome
Go to Top of Page
   

- Advertisement -