Syntax Error

  • Hi guys,

    I want to do something very simple: Here it goes:

    I create a table, then I am going to populate it based on a few things. The column I am populating in the new table is based off of the datetime value in the source table.

    So in other words,

    CREAT TABLE #Example

    ( RecordID int not null,

    NewColInd bit not null

    )

    EXEC

    ('

    INSERT INTO #Example

    SELECT sourcetbl.recordid AS RecordID,

    (CASE datetimecol

    WHEN datetimecol IS NOT NULL

    THEN 1

    ELSE 0

    END) AS NewColInd

    ')

    How do I correctly write this? (I excluded the joins for this writing, of course they exist in actual sql)

    Thanks for your hep.

  • You don't need the EXEC('').

    You also need to include the FROM (and possibly WHERE clauses) although, I think your second statement alludes to you just leaving them off the script..?

  • Thanks jpipes, yes I left off the where and from clauses for these purposes. I'm only interested in the eror I'm getting from the CAE statement.

    It really doesn't make much of a difference about the "EXEC (' " it will run regardless.

    I just need some input on that dangnabbitt CASE ststement.

    Thanks again,

    Chris

  • Try:

    CASE

    WHEN datetimecol IS NOT NULL THEN 1 ELSE 0 END

    🙂

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

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