Can a variable have three values?

  • Hi I'm an entry level SQL Developer. Let me explain a scenario to you, I have a table with set of File names(File name is one of the column in the table with jobs(Path of the job in it)). My job is to replace say three different names Sa,Ba,Sb,Bb,Sc,Bc with two other names say X,Y (all of the prefixes with S are replaced with X while B with Y).

    Since they are thousand of rows in that column I'm actually thinking of define two variable along with a cursor. So that these variables go and pick those appropriate Letters in the table.

    But the question is can two variables pick three values each?

    Thanks in Advance

  • Firstly I would avoid cursors unless you are absolutely certain you need one. (And even then there is probably a better way).

    I think all you need is something like:

    update t

    set col = case left(col,1)

    when 's' then 'X'

    when b' then 'Y'

    else col end

    where left(col,1) in ('s','b')

    If you need more explanation of that please post a sample table and data and I (or someone else) will be able to test the code and explain more.

    Mike

  • Thanks Mike.....This might really help me, definitely i will post a table tomorrow with the data atleast top 20. Once again Thanks.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply