Need help with Select statement

  • Hi all,

    i have put to gather the following query and i am getting the following syntax errors...could you assist me in finding out what is incorrect or missing in the following query?

    SELECT top 50 i_columnname

    getdate() as CURRENT_date

    (select count(*) from dbo.v_HD_DW_table_name

    WHERE I_RecId = T_ParentLink_RecID

    AND (

    where datepart(yy, GETDATE()) = datepart(yy, I_columnname)

    and datepart(mm, GETDATE()) = datepart(mm, i_columnname)

    and datepart(dd, GETDATE()) = datepart(dd, i_AssignedDateTime)

    )) as new_tasks,

    (select count(*) from dbo.v_HD_DW_table_name

    WHERE I_RecId = T_ParentLink_RecID

    AND (

    where datepart(yy, GETDATE()) = datepart(yy, T_ResolvedDateTime)

    and datepart(mm, GETDATE()) = datepart(mm, T_ResolvedDateTime)

    and datepart(dd, GETDATE()) = datepart(dd, T_ResolvedDateTime)

    )) as RESOLVED_TASKS,

    (select count(*) from dbo.v_HD_DW_ITSM_Tasks Task where

    WHERE I_RecId = T_ParentLink_RecID

    AND (

    where datepart(yy, GETDATE()) BETWEEN datepart(yy, i_columnname) and datepart(yy, i_columnname)

    and datepart(mm, GETDATE()) BETWEEN datepart(mm, i_columnname) AND datepart(mm, ISNULL(i_columnname, GETDATE()))

    and datepart(dd, GETDATE()) = datepart(dd, i_columnname) AND datepart(dd, i_columnname)

    )) as OPEN_tasks

    group by datepart(yy, GETDATE()), datepart(mm, GETDATE()), datepart(dd, GETDATE())

    order by CURRENT_date --yr, mm, dd

    the following syntax errors i am encountering...

    Msg 156, Level 15, State 1, Line 4

    Incorrect syntax near the keyword 'CURRENT_date'.

    Msg 156, Level 15, State 1, Line 12

    Incorrect syntax near the keyword 'where'.

    Msg 156, Level 15, State 1, Line 22

    Incorrect syntax near the keyword 'WHERE'.

    Msg 156, Level 15, State 1, Line 36

    Incorrect syntax near the keyword 'WHERE'.

    please advice how i can get beyond these or what i might be doing wrong.

    thanks in advance.

  • There is a bit of work to be done on this query. It would greatly help if you could provide the table definition script that you are looking to pull from so that we can have a better idea on how to help. If you want to try to work through this yourself the following example script should help you.

    select column1, column2, column3

    from SomeTable

    where column1 = SomeValue or (column2 = SomeValue and column3 = SomeValue)

    Notice that there is a comma between each column mentioned in the select statement. Also notice that there is only one WHERE clause used in the query and any predicates (or criteria) that are specified in this clause are tied together by the use of AND or OR.

    I do hope this helps and again please post some table definition scripts if you would like some further help.

    David

    @SQLTentmaker

    “He is no fool who gives what he cannot keep to gain that which he cannot lose” - Jim Elliot

  • Thank you David,

    i figured it out...the error was due to the fact i had where in the query twice which was unnecessary.

    and a few syntax as the error mentioned.

    thanks again.

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

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