By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,587 Members | 1,070 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,587 IT Pros & Developers. It's quick & easy.

Switch Function not working properly

P: 1
I am receving an "#Error" when I run the Switch function that I created.
Switch([Expr1]='45H4',"4502",[Expr1]='79H1',"7922",[Expr1]='79H2',"7982",[Expr1]='79H3',"7983",
[Expr1]='79H5',"7999",[Expr1]='79V3',"7963",[Expr1]='79V4',"7964",[Expr1]=8500,"7900",
[Expr1]=8501,"7901",[Expr1]=8505,"7905",[Expr1]=8511,"7911")

My output looks like this:
ID AnalysisDept Expr1 Expr2
1 6079H2 79H2 #Error
2 6079H4 79H4 #Error
3 6079H1 79H1 #Error
4 357917 7917
5 357902 7902
6 357981 7981
7 3545H4 45H4 #Error
Sep 11 '07 #1
Share this Question
Share on Google+
1 Reply


FishVal
Expert 2.5K+
P: 2,653
I am receving an "#Error" when I run the Switch function that I created.
Switch([Expr1]='45H4',"4502",[Expr1]='79H1',"7922",[Expr1]='79H2',"7982",[Expr1]='79H3',"7983",
[Expr1]='79H5',"7999",[Expr1]='79V3',"7963",[Expr1]='79V4',"7964",[Expr1]=8500,"7900",
[Expr1]=8501,"7901",[Expr1]=8505,"7905",[Expr1]=8511,"7911")

My output looks like this:
ID AnalysisDept Expr1 Expr2
1 6079H2 79H2 #Error
2 6079H4 79H4 #Error
3 6079H1 79H1 #Error
4 357917 7917
5 357902 7902
6 357981 7981
7 3545H4 45H4 #Error
Hi, there.

You compare [Expr1] with strings and numbers. So what is the actual type of [Expr1]?

And, G..d save us, the more natural way to do it in database is to create an additional table with two fields, one for value to be compared with and one for value to be returned, then you can simply join this table with your one having not dealt with all these huge switch or iif comparisons. This is more flexible and performs better.
Sep 11 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.