SQL Query with multiple values in one column

Posted by lp1 on Stack Overflow See other posts from Stack Overflow or by lp1
Published on 2010-05-10T03:10:36Z Indexed on 2010/05/10 3:18 UTC
Read the original article Hit count: 299

Filed under:
|
|

I've been beating my head on the desk tring to figure this one out. I have a table that stores job information, and reasons for a job not being completed. The reasons are numeric,01,02,03,etc. You can have two reason for a pending job. If you select two reasons, they are stored in the same column, seperated by a comma. This is anExample from the JOBID table:

Job_Number User_Assigned PendingInfo

1 user1 01,02

Now, there is another table named Pending, that stores what those values actually represent. 01=Not enough info, 02=Not enough time, 03=Waiting Review. Example:

Pending_Num PendingWord

01 Not Enough Info

02 Not Enough Time

What I'm trying to do is query the database to give me all the job numbers, users, pendinginfo, and pending reason. I can break out the first value, but can't figure out how to do the second. What my limited skills have so far:

*select Job_number,user_assigned,SUBSTRING(pendinginfo,0,3),pendingword from jobid,pending where SUBSTRING(pendinginfo,0,3)=pending.pending_num and pendinginfo!='00,00' and pendinginfo!='NULL'*

What I would like to see for this example would be:

Job_Number User_Assigned PendingInfo PendingWord PendingInfo PendingWord

1 User1 01 Not Enough Info 02 Not Enough Time

Thanks in advance

© Stack Overflow or respective owner

Related posts about sql

Related posts about sql-server