Need to know whether the script is correct or not as converted from MS access to T-sql

Just want to check it this correct or not

Access Script :

 --IIf([ss type]="stocking",IIf([ZZZ - Name Table v2_1]![Purchasing]="Y",[agent],IIf([ZZZ - Name Table v2_2]![Purchasing]="Y",[owner],IIf([ZZZ - Name Table v2]![Purchasing]="Y",[salesman],[part admin]))),IIf([ZZZ - Name Table v2_1]![Purchasing]="Y",[agent],IIf([ZZZ - Name Table v2_2]![Purchasing]="Y",[owner],IIf([ZZZ - Name Table v2]![Purchasing]="Y",[salesman],Null)))) AS [Final Owner],


T-Sql Script :

Case When [ss type] = 'stocking' THEN
 (Case [ZZZ - Name Table v2_1][^][Purchasing]='Y' then [agent]
else(Case when [ZZZ - Name Table v2_2][^][Purchasing]='Y' then [owner] else
(Case When [ZZZ - Name Table v2][^][Purchasing]='Y' then [salesman] else [part admin] end )end)end)
ELSE
(Case When [ZZZ - Name Table v2_1][^][Purchasing]='Y' then [agent] else
(Case when [ZZZ - Name Table v2_2][^][Purchasing]='Y' then [owner] else
(Case When [ZZZ - Name Table v2][^][Purchasing]='Y' then [salesman] else Null end )end)end) END) AS [Final Owner],
AparanjithAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

chaauCommented:
When writing CASE statement you do not need to nest them the way you do with the Iif. Treat CASE as a SWITCH function (with an addition of ELSE, which SWITCH lacks).
Case When [ss type] = 'stocking' THEN
  (Case [ZZZ - Name Table v2_1].[Purchasing]='Y' then [agent]
   when [ZZZ - Name Table v2_2].[Purchasing]='Y' then [owner] 
   When [ZZZ - Name Table v2].[Purchasing]='Y' then [salesman] 
   else [part admin] end )
ELSE
  (Case When [ZZZ - Name Table v2_1].[Purchasing]='Y' then [agent]
   when [ZZZ - Name Table v2_2].[Purchasing]='Y' then [owner]
   When [ZZZ - Name Table v2].[Purchasing]='Y' then [salesman] 
   else Null end) 
END AS [Final Owner],

Open in new window



BTW, to separate table name and column in T-SQL you need to use a dot (.)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AparanjithAuthor Commented:
Hey Chaau,
                     As you can see in MS access script it has ! symbol, so I thought I should replace that with in sql script as [^]. Correct me if I am wrong,
 As you said, the table name and column name is differentiated with . in sql. Just suggest me what should I use in lace ! in sql, as when I see for wildcard wich replaces !  in sql, I found [^] symbol. Answer would be appriciated.

Thanks,
Aparanjit
0
chaauCommented:
What is [ZZZ - Name Table v2_1] and what is [Purchasing]? If the former is a table and the latter is a column then you need to use [ZZZ - Name Table v2_1].[Purchasing] syntax
0
AparanjithAuthor Commented:
Thanks Chaau, I appreciate it.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.