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 2005 Forums
 Transact-SQL (2005)
 Logical field in View

Author  Topic 

bkbinani
Starting Member

15 Posts

Posted - 2011-12-07 : 08:31:01
Dear Expert,

I m in little bit trouble. I wish to create a view with addtional logical field (BIT) which is not in primary (sourc Table)

I used following Codes but not success.

declare @lyn bit
set @lyn=0
create view vew_mst_led as
select @lyn as YES_NO ,cled_name,cled_code,nled_type,nled_bal from mst_led


Please help.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-07 : 08:34:50
you can use variable inside view like this. you need to include value as a constant or use procedure instead.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

bkbinani
Starting Member

15 Posts

Posted - 2011-12-07 : 08:43:50
quote:
Originally posted by visakh16

you can use variable inside view like this. you need to include value as a constant or use procedure instead.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/




Thanx Sir. My hats off 2 u. Great that u r MVP.

Your reply is not clear to me as I m Not expert rather I m Novice. Plz give more light. I wud grateful for your response with example.

TIA
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-07 : 08:51:10
you need to write it as a procedure if you want to use variables like this

create proc vew_mst_led
@lyn bit=0
as
select @lyn as YES_NO ,cled_name,cled_code,nled_type,nled_bal
from mst_led
go


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

bkbinani
Starting Member

15 Posts

Posted - 2011-12-07 : 09:03:09
quote:
Originally posted by visakh16

you need to write it as a procedure if you want to use variables like this

create proc vew_mst_led
@lyn bit=0
as
select @lyn as YES_NO ,cled_name,cled_code,nled_type,nled_bal
from mst_led
go


Thanx sir.

But wud it be a 'view'. I wish to use VIEW for different purspose.

Please
------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/



Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-07 : 09:07:27
you cant have a variable inside view. view is just a virtual table with definition. you cant make it interactive by adding variables etc.
for that you've to use procedures like what i've shown.
Who suggested you to use view for above scenario?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

bkbinani
Starting Member

15 Posts

Posted - 2011-12-08 : 07:24:09
quote:
Originally posted by visakh16

you cant have a variable inside view. view is just a virtual table with definition. you cant make it interactive by adding variables etc.
for that you've to use procedures like what i've shown.
Who suggested you to use view for above scenario?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Thanx sir.
There was a confusion with Temp Table VS. View. I was taking view table as tmp.
Sorry for troubl.

Very very thanx for your reply to make me understand.

Nice.

Hope 2 c again.


Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-08 : 07:36:01
no problem
you're welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -