Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Coromandel
Starting Member
1 Post |
Posted - 2003-10-02 : 11:08:19
|
| I'm trying to create a view that includes a variable in the select statement, along the following lines ...CREATE VIEW nicktest ASDECLARE @CurrYear intSET @CurrYear=CASE .... GETDATE()...ENDSELECT ...The declaration and select statement works fine until I try to create a view from it. It insists on the create view being the first line and if I list it as above I get the following message"Server: Msg 156, Level 15, State 1, Procedure trdm_SEEDA_nicktest, Line 2Incorrect syntax near the keyword 'DECLARE'."Does this need to be part of something else e.g procedure? |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2003-10-02 : 12:54:32
|
| You can't do this in a view. What you are trying to do can be done in a stored procedure. A view is just a select statement and that's it. A stored procedure can have much more logic. Take a look at the information about creating stored procedures in SQL Server Books Online.Tara |
 |
|
|
|
|
|