You must Sign In to post a response.
  • Category: SQL Server

    I tried but it is not working in sql query

    My tried query as follows

    select 1, convert(char(12),b.cbm_batch_start_dt,106) as Startdt,
    convert(char(12),b.cbm_batch_end_dt,106) as Enddt,a.course as Course from tb_rankwise_coursesettings as a,CO_BATCH_MASTER as b
    where a.course = b.cmn_minor_code and a.Rank = 'CHENGR' and b.cbm_active <> 'd' and
    b.cbm_batch_start_dt between '2015-08-01 00:00:00.000' and '2015-12-30 00:00:00.000'
    order by b.cbm_batch_start_dt asc

    When i run the above query output as follows

    Startdt Enddt Course
    10 Aug 2015 21 Aug 2015 REO
    24 Aug 2015 04 Sep 2015 REO
    14 Dec 2015 25 Dec 2015 REO


    But i want the output as follows
    REO
    10 Aug 2015 21 Aug 2015
    24 Aug 2015 04 Sep 2015
    14 Dec 2015 25 Dec 2015


    for getting above ouput i write the query as follows



    declare @t1 table(id int,startdt varchar(50),enddt varchar(50),course varchar(max))
    insert into @t1
    select 1, convert(char(12),b.cbm_batch_start_dt,106) as Startdt,
    convert(char(12),b.cbm_batch_end_dt,106) as Enddt,a.course as Course from tb_rankwise_coursesettings as a,CO_BATCH_MASTER as b
    where a.course = b.cmn_minor_code and a.Rank ='CHENGR' and b.cbm_active <> 'd' and a.Active<> 'd' and b.cbm_batch_start_dt between '2015-08-01 00:00:00.000' and '2015-12-30 00:00:00.000'
    order by b.cbm_batch_start_dt asc
    FROM @t1
    unpivot
    {
    REO
    FOR [course] IN (REO)
    } unpiv;


    but when i run the above query error as follows

    Incorrect syntax near the keyword 'FROM'

    what is the mistake in my above query.

    What I have tried:

    My tried query as follows

    select 1, convert(char(12),b.cbm_batch_start_dt,106) as Startdt,
    convert(char(12),b.cbm_batch_end_dt,106) as Enddt,a.course as Course from tb_rankwise_coursesettings as a,CO_BATCH_MASTER as b
    where a.course = b.cmn_minor_code and a.Rank = 'CHENGR' and b.cbm_active <> 'd' and
    b.cbm_batch_start_dt between '2015-08-01 00:00:00.000' and '2015-12-30 00:00:00.000'
    order by b.cbm_batch_start_dt asc

    When i run the above query output as follows

    Startdt Enddt Course
    10 Aug 2015 21 Aug 2015 REO
    24 Aug 2015 04 Sep 2015 REO
    14 Dec 2015 25 Dec 2015 REO


    But i want the output as follows
    REO
    10 Aug 2015 21 Aug 2015
    24 Aug 2015 04 Sep 2015
    14 Dec 2015 25 Dec 2015


    for getting above ouput i write the query as follows



    declare @t1 table(id int,startdt varchar(50),enddt varchar(50),course varchar(max))
    insert into @t1
    select 1, convert(char(12),b.cbm_batch_start_dt,106) as Startdt,
    convert(char(12),b.cbm_batch_end_dt,106) as Enddt,a.course as Course from tb_rankwise_coursesettings as a,CO_BATCH_MASTER as b
    where a.course = b.cmn_minor_code and a.Rank ='CHENGR' and b.cbm_active <> 'd' and a.Active<> 'd' and b.cbm_batch_start_dt between '2015-08-01 00:00:00.000' and '2015-12-30 00:00:00.000'
    order by b.cbm_batch_start_dt asc
    FROM @t1
    unpivot
    {
    REO
    FOR [course] IN (REO)
    } unpiv;


    but when i run the above query error as follows

    Incorrect syntax near the keyword 'FROM'

    what is the mistake in my above query.
  • #764587
    Hi rao,
    This is the same question you have posted 3rd time.
    Its my humble request to you that for same issue, instead of posting your sql scripts multiple times on forum, you can comment on a single thread. That's the way we can try resolve your issue within time.
    Please refer this for your answer:
    http://www.dotnetspider.com/forum/344036-Convert-the-columns-into-rows.aspx
    Thanks & Regards,
    Shashikant Gurav
    shashikantgurav22@gmail.com

  • #764594
    Hi,

    In Microsoft SQL, it's follows some syntaxes we should follow the syntaxes perfectly, then only it wont give any errors, if you are omit the syntaxes obviously it will throw errors like this "Incorrect syntax near the keyword 'FROM' ".

    As per your error message; the error message clearly states that you are not followed the syntaxes at FROM keyword, please recheck the query and resolve it.

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/


Sign In to post your comments