Thank you very much! I will give it a try.
Main Topics
Browse All TopicsI have a SQL view that has many case statements to create columns. Depending on what type of a sales order it is the data come from different tables. I am thinking that I can accomplish the same thing with one larger case statement that would be more efficient. Here is a sample of the code.
tsoSOHeaderExtAttribs_NCI.
tsoSOLine.Description, tsoSOLine.ExtCmnt, tsoSOLine.SOLineKey, tsoSOLine.SOLineNo, tsoSOLineDist.ShipDate AS soldShipDate, tsoSOLineDist.QtyOrd AS QtyOrd,
Case
When tsoSalesOrder.UserFld4 = 'EDI' Then
timItemExtAttribs_NCI.NCIT
tsoSOLineExtAttribs_NCI.NC
End As NCIType,
Case
When tsoSalesOrder.UserFld4 = 'EDI' Then
timItemExtAttribs_NCI.Draw
tsoSOLineExtAttribs_NCI.Dr
End AS solxDrawingNo,
tsoSOLineExtAttribs_NCI.Pa
Case
When tsoSalesOrder.UserFld4 = 'EDI' Then
timItemExtAttribs_NCI.Widt
tsoSOLineExtAttribs_NCI.Wi
End As WidthDec,
Case
When tsoSalesOrder.UserFld4 = 'EDI' Then
timItemExtAttribs_NCI.Leng
tsoSOLineExtAttribs_NCI.He
End As HeightDec,
tsoSOLineExtAttribs_NCI.Pa
Case
When tsoSalesOrder.UserFld4 = 'EDI' Then
timItemExtAttribs_NCI.SqFt
tsoSOLineExtAttribs_NCI.Un
End As UnitSFArea,
Case
When tsoSalesOrder.UserFld4 = 'EDI' Then
cstm_nc_rtf_board_table.Bo
tsoSOLineExtAttribs_NCI.Bo
End AS solxBoardType
Thank you in advance for your help
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: aneeshattingalPosted on 2009-11-03 at 11:26:23ID: 25732510
your case statement seems to be fine, here is another version, compare this with your original query and check the performance
ResComm AS sohxResComm, tsoSOHeaderExtAttribs_NCI. InvoiceIns tructions AS sohxInvoiceInstructions, timItem.ItemID, IType, timItemExtAttribs_NCI.Draw ingNbr AS solxDrawingNo, intbacks As solxPaintbacks,timItemExtA ttribs_NCI .WidthDec, thDec As HeightDec,tsoSOLineExtAttr ibs_NCI.Pa nelHeight As PanelHeight, As UnitSFArea, stm_nc_rtf_board_table.Boa rdName AS solxBoardType
ResComm AS sohxResComm, tsoSOHeaderExtAttribs_NCI. InvoiceIns tructions AS sohxInvoiceInstructions, timItem.ItemID, IType, awingNo, intbacks As solxPaintbacks, dthDec , ightDec, nelHeight As PanelHeight, itSFArea, ardType
SELECT tsoSOHeaderExtAttribs_NCI.
tsoSOLine.Description, tsoSOLine.ExtCmnt, tsoSOLine.SOLineKey, tsoSOLine.SOLineNo, tsoSOLineDist.ShipDate AS soldShipDate, tsoSOLineDist.QtyOrd AS QtyOrd,
tsoSOLineExtAttribs_NCI.NC
tsoSOLineExtAttribs_NCI.Pa
timItemExtAttribs_NCI.Leng
timItemExtAttribs_NCI.SqFt
FROM ....
WHERE tsoSalesOrder.UserFld4 = 'EDI'
UNION ALL
SELECT tsoSOHeaderExtAttribs_NCI.
tsoSOLine.Description, tsoSOLine.ExtCmnt, tsoSOLine.SOLineKey, tsoSOLine.SOLineNo, tsoSOLineDist.ShipDate AS soldShipDate, tsoSOLineDist.QtyOrd AS QtyOrd,
tsoSOLineExtAttribs_NCI.NC
tsoSOLineExtAttribs_NCI.Dr
tsoSOLineExtAttribs_NCI.Pa
tsoSOLineExtAttribs_NCI.Wi
tsoSOLineExtAttribs_NCI.He
tsoSOLineExtAttribs_NCI.Pa
tsoSOLineExtAttribs_NCI.Un
tsoSOLineExtAttribs_NCI.Bo
FROM ....
WHERE tsoSalesOrder.UserFld4 <> 'EDI'