locked
The code does't work RRS feed

  • Question

  • User-254743730 posted

    Hi,

     i got  Incorrect syntax near '='.

      what mistake i done there...... please any one help me

    select * from tngf_CMS where ModuleId = 77 and Flag = 1 and Status = 1 ORDER BY CONVERT(datetime, EleventhContent == null ) THEN CONVERT(datetime, FourthContent < GetDate()) ELSE CONVERT(datetime, EleventhContent < GetDate)

    Monday, August 20, 2012 3:04 AM

Answers

  • User3866881 posted

    Hi,

    As far as I see——

    1)== can be used in C# instead of SQL syntax. And you cannot use == or = directly in the SQL statement. You have to use "Is" instead.

    2)case can be used like this:

    select * from xxx

    where ……

    order by

    (

        case when [YourDateTimeField]<getdate() then 1
        else 0

        END

    )

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, August 21, 2012 9:13 PM

All replies

  • User-2005691517 posted

    The order by clause is wrong. You cannot use ==

    What are you trying to order by? Can you explain?

    Monday, August 20, 2012 3:28 AM
  • User-254743730 posted

    i want the date in order. i get the record in database for based on two condition.

    Two column field.  first column is my start date. second column is end date.

    if user give only start date mean 

    fitst column field based data to be display

    this case was execute.

     string date = "CONVERT(datetime, FourthContent,101)";

    order = "ORDER BY CASE WHEN (" + date + " < GetDate()) THEN 1 ELSE 0 END,(CONVERT(datetime, FourthContent))";

    if first and end date mean i want to display  data based on end date .

    Monday, August 20, 2012 3:43 AM
  • User3866881 posted

    Hi,

    As far as I see——

    1)== can be used in C# instead of SQL syntax. And you cannot use == or = directly in the SQL statement. You have to use "Is" instead.

    2)case can be used like this:

    select * from xxx

    where ……

    order by

    (

        case when [YourDateTimeField]<getdate() then 1
        else 0

        END

    )

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, August 21, 2012 9:13 PM