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.
Author |
Topic |
mcinvalek
Starting Member
5 Posts |
Posted - 2014-06-03 : 18:00:09
|
i have a table with a few hundred columns. Each SELECT statement, I list each of the columns, this is taking lots and lots of space and it is difficult to review the code due to its lengthBelow, I have to list out every column when I only want to use case logic on 1 column. In the next step I will have to list out every single column againSELECT ACCT1_NO ,ACCT1_DT ,ACCT1_RISK ,ACCT1_RISK_WEIGHT ,ACCT1_CUSTOMER_NAME ,ACCT1_CUSTOMER_ADDRESS ,ACCT1_CUSTOMER_ST = CASE WHEN ACCT1_CUSTOMER_ST = ' ' THEN 'DC' END ,ACCT1_CUSTOMER_CITY ,ACCT1_CUSTOMER_ZIP --,THIS CONTINUES DOWN FOR ANOTHER 150 OR SO ACCTS.INTO #A1FROM STAGE.CUSTOMER_ACCTSIs there a way I can tell SQL to take all of the columns and then list the column where I want to do my case statement. Something like the code below (which will fail as ACCT1_CUSTOMER_ST will be listed twice.SELECT *,ACCT1_CUSTOMER_ST = CASE WHEN ACCT1_CUSTOMER_ST = ' ' THEN 'DC' ENDINTO #A1FROM STAGE.CUSTOMER_ACCTSthanks for all advise in advance |
|
bitsmed
Aged Yak Warrior
545 Posts |
Posted - 2014-06-03 : 18:17:55
|
Do one of the following:1) Make new column:SELECT *,ACCT1_CUSTOMER_ST = CASE WHEN ACCT1_CUSTOMER_ST = ' ' THEN 'DC' END AS ACCT1_CUSTOMER_ST_MANIPULATEDINTO #A1FROM STAGE.CUSTOMER_ACCTS 2) Copy the table, and run update afterwards:SELECT *INTO #A1FROM STAGE.CUSTOMER_ACCTS;UPDATE #A1SET ACCT1_CUSTOMER_ST = 'DC'WHERE ACCT1_CUSTOMER_ST = ' '; |
 |
|
|
|
|
|
|