| Author |
Topic |
|
tbarkdull
Starting Member
6 Posts |
Posted - 2009-05-06 : 14:42:50
|
| I have a SQL database that I have recently added a new field. To populate the field I need to create a statement tofor a [Location Code] = "HOI" and [Category] <> "Monitor" then [pcname]will be "C" = [Asset tag]I have about 10 such statements so IIF won't work. I'm new to SQL.Can someone please provide some help with the syntax |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-05-06 : 14:49:53
|
Your question is not fully clear, but maybe something like this?update tableset [Asset tag]= case when [Location Code] = 'HOI' and [Category] <> 'Monitor' then [pcname] when ... then ... else ... end No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
tbarkdull
Starting Member
6 Posts |
Posted - 2009-05-06 : 14:53:30
|
| sorryfor a [Location Code] = "HOI" and [Category] <> "Monitor" then [pcname]will be "C" + [Asset tag] |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-05-06 : 15:03:03
|
[code]update tableset [pcname]= case when [Location Code] = 'HOI' and [Category] <> 'Monitor' then 'C'+[Asset tag] -- if [Asset tag] is numeric: use 'C' + convert(varchar(255),[Asset tag]) when ... then ... else ... end[/code]I don't know much about [Asset tag] No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
tbarkdull
Starting Member
6 Posts |
Posted - 2009-05-06 : 15:11:56
|
| Thanks for your help. I am getting this error "Msg 156, Level 15, State 1, Line 1Incorrect syntax near the keyword 'table'. |
 |
|
|
tbarkdull
Starting Member
6 Posts |
Posted - 2009-05-06 : 15:16:44
|
| OK, I got it. forgot to replace table with table name |
 |
|
|
tbarkdull
Starting Member
6 Posts |
Posted - 2009-05-07 : 09:27:27
|
| How can I set it to clear all info in the PCname field first? |
 |
|
|
DonAtWork
Master Smack Fu Yak Hacker
2167 Posts |
Posted - 2009-05-07 : 10:36:42
|
| Before you blow up your database, follow the links in my signature. They have VERY good advice in them.[Signature]For fast help, follow this link:http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspxLearn SQL or How to sell Used CarsFor ultra basic questions, follow these links.http://www.sql-tutorial.net/ http://www.firstsql.com/tutor.htm http://www.w3schools.com/sql/default.asp |
 |
|
|
tbarkdull
Starting Member
6 Posts |
Posted - 2009-05-07 : 10:52:17
|
| Thanks DonAtWork |
 |
|
|
|