0

I am running into a problem with a view creation. I am trying to create a view with one of the fields being 7 weekdays before another date in the table. The field [Live_Date] is provided by the client and I need to create the date [ImageDeliveryDate].

I have removed all of the other fields since they are working. I have a problem somewhere in the syntax but I can't seem to find it.

Here is what I have written:

set @SQL = 'CREATE VIEW vw_GCS_Export
    As
    select  ''' + DATEADD(WEEKDAY,-7,''' + [Live_Date] + '+ CHAR(39) + ')' + CHAR(39) +' '' as [ImageDeliveryDate]

    from Sheet1$'

Can anyone shed some light on what I am messing up? I had this running at one point and now it is failing. I change the name of the field adding the underscore and that is the only change.

1
  • And for which database would that be? Things like "dynamic SQL" or stored procedures are highly vendor-specific - so we really need to know what concrete database you're working with.... Commented Apr 15, 2013 at 17:20

1 Answer 1

1

This works on my SQL Server 2008 R2 to create a view with the 7 day prior column:

declare @SQL nvarchar(255)
set @SQL = N'CREATE VIEW vw_GCS_Export As
select DATEADD(WEEKDAY,-7,[Live_Date])as [ImageDeliveryDate]
from Sheet1$'

But it's not clear to me why it needs to be dynamic and not just created with a regular drop/create, or what all of the quotes were intended for (including the CHAR(39)s).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.