dbTalk Databases Forums  

conditioned creation of view

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss conditioned creation of view in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
michael v
 
Posts: n/a

Default conditioned creation of view - 10-26-2005 , 09:50 AM






when doing this

create view viewname as select * from table1

no trouble but when doing this

if @temp 1 = 1 then
begin
create view viewname as select * from table1

suddenly sql server doesn't acknowledge the syntax in the create view
statement ? how come ?



Reply With Quote
  #2  
Old   
Darren Green
 
Posts: n/a

Default Re: conditioned creation of view - 10-26-2005 , 02:03 PM






michael v wrote:
Quote:
when doing this

create view viewname as select * from table1

no trouble but when doing this

if @temp 1 = 1 then
begin
create view viewname as select * from table1

suddenly sql server doesn't acknowledge the syntax in the create view
statement ? how come ?


The syntax is all wrong. @temp has not been declared. The if test has 3
parameters, @temp, 1 and another 1? If in SQL does not use then.

Crate view must be the first statement as well. Try this-

declare @temp int
set @temp = 1
if @temp = 1
begin
exec('create view viewname as select * from sysobjects')
end

--
Darren Green
http://www.sqldts.com
http://www.sqlis.com


Reply With Quote
  #3  
Old   
michael v
 
Posts: n/a

Default Re: conditioned creation of view - 10-27-2005 , 02:54 AM



thanx darren

I did declare it but didn't show it but i was missing the exec statement.

didn't know that this was needed

"Darren Green" <darren.green (AT) reply-to-newsgroup-sqldts (DOT) com> wrote

Quote:
michael v wrote:
when doing this

create view viewname as select * from table1

no trouble but when doing this

if @temp 1 = 1 then
begin
create view viewname as select * from table1

suddenly sql server doesn't acknowledge the syntax in the create view
statement ? how come ?


The syntax is all wrong. @temp has not been declared. The if test has 3
parameters, @temp, 1 and another 1? If in SQL does not use then.

Crate view must be the first statement as well. Try this-

declare @temp int
set @temp = 1
if @temp = 1
begin
exec('create view viewname as select * from sysobjects')
end

--
Darren Green
http://www.sqldts.com
http://www.sqlis.com



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.