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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Creatre View

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-09-26 : 07:42:09
Julia writes "Hi. I need create a view that will check the server id.Depend on the Server id I need to have a different select statment inside this view. For example:
Create View_SomeName
IF ServerID = 1
BEGIN
SELECT * FROM TABLE_NAME1
END
ELSE
BEGIN
SELECT * FROM TABLE_NAME2
END
What I am doing wrong here?? I am getting SQL syntax error.
Thank you, all."

JoeNak
Constraint Violating Yak Guru

292 Posts

Posted - 2006-09-26 : 07:46:10
Try replacing your if statement...

IF @@SERVERNAME = 'ServerName'
Go to Top of Page

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2006-09-26 : 07:59:56
I dont think what you are trying to do can be achvied using view..


Chirag
Go to Top of Page

JoeNak
Constraint Violating Yak Guru

292 Posts

Posted - 2006-09-26 : 08:06:14
duh.. View...I have to read a little closer.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-09-26 : 09:26:11
Why dont you use Stored preocedure?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

LoztInSpace
Aged Yak Warrior

940 Posts

Posted - 2006-09-27 : 00:17:03
select * from table_1
where
@@servername='1'
union all
select * from table_2
where
@@servername='2'

Seems a bit of a dodgy requirement though. What's your objective here?
Go to Top of Page
   

- Advertisement -