2

Hi i have two tables Agents, Skills and target query as below

Agents

-------------------------------------
PF       |Name       |HireDate       |
---------|-----------|---------------|
54       |Jack       |01-Jan-2012    |
55       |Aline      |01-Jan-2012    |
-------------------------------------

Skills

-------------------------------------------------------------
PF       |Writing    |Swimming       |KickOff    |Shopping   |
---------|-----------|---------------|-----------------------
54       |Null       |01-Dec-2012    |Null       |Null       |
55       |01-Mar-2012|01-FeB-2012    |Null       |15-Nov-2012|
-------------------------------------------------------------

I want query to select PF, Hiredate from Agents table and avaliable skills from skills table, The date on skills tables means that agents learned this skill on this data, but if there is null value that means agents didn't have this skill, but i want to replace date with column name The below table explane what is my query

MyQuery

------------------------------------------------------
PF       |HireDate       |Avalivble skills            |
---------|---------------|----------------------------|
54       |01-Jan-2012    |Swimming                    |
55       |01-Jan-2012    |Writing, Swimming, Shopping |
------------------------------------------------------
1
  • What RDBMS you are using? SQL Server? MySQL? Oracle? DB2? etc... Commented Jan 31, 2013 at 14:13

1 Answer 1

1
select  PF
,       HireDate
,       replace(
            iif(Writing is null;'';'Writing, ') +
            iif(Swimming is null;'';'Swimming, ') +
            iif(KickOff is null;'';'KickOff, ') +
            iif(Shopping is null;'';'Shopping, ') + '$';
            ', $'; '')
from    Agents a
join    Skills s
on      s.PF = a.PF
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks but its return error "Syntax error (missing operator)"
You'll need to trim off the trailing ', '
@openshac: I guess you could... not always important though.
Depending on your locale, try to relace the ; with , ?
Tested in Euro locale MS Access: select a.PF , HireDate , replace( iif(Writing is null,'','Writing, ') + iif(Swimming is null,'','Swimming, ') + iif(KickOff is null,'','KickOff, ') + iif(Shopping is null,'','Shopping, ') + '$', ', $', '') from Agents a inner join Skills s on s.PF = a.PF

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.