Hi Jeremy,

I tried but it's not working

MSSQL raise an error "Incorrect syntax near the keyword 'UNPIVOT'".

It is because a "comma", right after the alias "p1" and before the operator 
UNPIVOT, is found in the SQL statement

Please advise. thank you.

Kenneth

On Thursday, June 21, 2018 at 12:25:28 PM UTC-7, Jeremy Evans wrote:
>
> On Thursday, June 21, 2018 at 10:41:52 AM UTC-7, lkfken wrote:
>>
>> Hi Jeremy,
>>
>> Sorry about that. I misunderstood on what you need.
>>
>> Here is the SQL statement 
>> SELECT NAME, 
>>        dates, 
>>        source 
>> FROM   (SELECT NAME, 
>>                a_date, 
>>                b_date, 
>>                c_date 
>>         FROM   test 
>>         WHERE  NAME = 'TOM') AS p1 
>>        UNPIVOT ( dates 
>>                FOR source IN (a_date, 
>>                               b_date, 
>>                               c_date) ) AS p2; 
>>
>> so what I want is to have "p1" come from Sequel::Dataset (ie: Test.toms, 
>> Test.joes, etc) instead of hard code it into this SQL statement.
>>
>
> This should work, and produce the same SQL (modulo identifier quoting):
>
>  DB.select(:NAME, :dates, :source).
>   from(DB[:test].select(:NAME, :a_date, :b_date, 
> :c_date).where(:name=>'TOM').as(:p1),
>        Sequel.lit("UNPIVOT (dates FOR source IN (a_date, b_date, 
> c_date))").as(:p2))
>
> Thanks,
> Jeremy
>

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sequel-talk+unsubscr...@googlegroups.com.
To post to this group, send email to sequel-talk@googlegroups.com.
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to