| Author |
Topic |
|
michpaust
Starting Member
21 Posts |
Posted - 2005-04-19 : 14:17:26
|
| Me again. I am doing an update and I have the following code UpdateAr_temp set Ar_temp.inv_num = CASE WHEN SUBSTRING([inv_num],1,1)='0' THEN '7' WHEN SUBSTRING([inv_num],1,1)='1' THEN '7'endthat throws the following error when I run itServer: Msg 515, Level 16, State 2, Line 1Cannot insert the value NULL into column 'Inv_Num', table 'plusdb.dbo.AR_Temp'; column does not allow nulls. UPDATE fails.The statement has been terminatedThe database system that I am pulling this info from is a little quirky and it cuts off the first digit, which is a seven from the inv_num. What i am trying to do is add the seven after the fact but can't seem to quite get there.Thanks again |
|
|
nathans
Aged Yak Warrior
938 Posts |
Posted - 2005-04-19 : 14:48:20
|
What about the CASE ELSE ?? This is why the NULL INSERT error is thrown. Also, the way you are writing the CASE will update the entire number to a 7, not append a 7 to the beginning. Is this what you want?DECLARE @Ar_temp TABLE (inv_num CHAR(5) NOT NULL)INSERT INTO @Ar_tempSELECT 12345 UNION SELECT 54321SELECT inv_num, SUBSTRING([inv_num],1,1)FROM @Ar_tempUPDATE @Ar_temp SET inv_num = CASE WHEN SUBSTRING([inv_num],1,1) = '0' THEN '7' WHEN SUBSTRING([inv_num],1,1) = '1' THEN '7' ELSE inv_num ENDSELECT inv_num, SUBSTRING([inv_num],1,1)FROM @Ar_temp |
 |
|
|
michpaust
Starting Member
21 Posts |
Posted - 2005-04-19 : 14:56:29
|
| Nathans, that worked perfectly. I was trying to append the 7 to a number and didn't even think of doing a case else. I've had my head buried in code all day and got stuck on just figuring it out using just the case statement. Sometime it takes another pair of eyes.Thanks much |
 |
|
|
michpaust
Starting Member
21 Posts |
Posted - 2005-04-19 : 15:01:47
|
| oops, Just checked the Ar_temp table and it replaced the entire number with 7. I just need to append it to the front of a seven difit number. Is there another way I can do this? |
 |
|
|
Bustaz Kool
Master Smack Fu Yak Hacker
1834 Posts |
Posted - 2005-04-19 : 15:22:06
|
| That's priceless...HTH=================================================================Every act of conscious learning requires the willingness to suffer an injury to one's self-esteem. That is why young children, before they are aware of their own self-importance, learn so easily; and why older persons, especially if vain or important, cannot learn at all. -Thomas Szasz, author, professor of psychiatry (1920- ) |
 |
|
|
michpaust
Starting Member
21 Posts |
Posted - 2005-04-19 : 15:43:11
|
| Nathans I am soo sorry, I was just so excited that I didn't get an error that I assumed it worked. Now I'm stuck still trying to figure out how to append the 7 and not replace the existing number with a 7. Still asking pitifully for help on this matter |
 |
|
|
nathans
Aged Yak Warrior
938 Posts |
Posted - 2005-04-19 : 16:15:44
|
| ... THEN '7' + inv_num buztaz, dont make me laugh :) |
 |
|
|
michpaust
Starting Member
21 Posts |
Posted - 2005-04-19 : 16:24:30
|
| Thank you nathans. This time I checked and it worked. My first born will be named nathan! |
 |
|
|
nathans
Aged Yak Warrior
938 Posts |
Posted - 2005-04-19 : 16:25:15
|
| and tell us again why the database "cuts off the first digit?" Its a little quirky? That doesnt sound good. |
 |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2005-04-19 : 17:14:37
|
Must have forgot to run SET QUIRKY OFFquote: Originally posted by nathans and tell us again why the database "cuts off the first digit?" Its a little quirky? That doesnt sound good.
CODO ERGO SUM |
 |
|
|
|