SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 view problem
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

rajasekhar857
Constraint Violating Yak Guru

396 Posts

Posted - 01/27/2010 :  09:05:30  Show Profile  Reply with Quote
hi i want an input parameter view where if record exists it should return 1 and if not exists it should return zero.

my view is something like this.

Create View [dbo].[emrVBUserInfo]@group_id varchar(50)
as
SELECT FEATURE_REF_ID,GROUP_ID,EMR_FEATURE_ID FROM EMRFEATUREREFERENCE WHERE GROUP_ID=@group_id AND EMR_FETAURE-ID=48
GO

madhivanan
Premature Yak Congratulator

India
22755 Posts

Posted - 01/27/2010 :  09:08:57  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
You should make use of a stored procedure. View wont do what you want

Madhivanan

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

Kristen
Test

United Kingdom
22403 Posts

Posted - 01/27/2010 :  09:10:38  Show Profile  Reply with Quote
You can't have a parameter in a VIEW

Create View [dbo].[emrVBUserInfo] @group_id varchar(50)
as
SELECT FEATURE_REF_ID,GROUP_ID,EMR_FEATURE_ID FROM EMRFEATUREREFERENCE WHERE GROUP_ID=@group_id AND EMR_FETAURE-ID=48
GO

and then select using

SELECT * FROM [dbo].[emrVBUserInfo]
WHERE GROUP_ID = some ID
Go to Top of Page

rajasekhar857
Constraint Violating Yak Guru

396 Posts

Posted - 01/27/2010 :  09:12:34  Show Profile  Reply with Quote
then if record exists i should return 1 or else 0 how to handle that
Go to Top of Page

rajasekhar857
Constraint Violating Yak Guru

396 Posts

Posted - 01/27/2010 :  09:14:38  Show Profile  Reply with Quote
can you give me an example of how to do this with stored procedure
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22755 Posts

Posted - 01/27/2010 :  09:26:50  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote

Create procedure [dbo].[emrVBUserInfo]
(
@group_id varchar(50)
)
as
If exists(SELECT FEATURE_REF_ID,GROUP_ID,EMR_FEATURE_ID FROM EMRFEATUREREFERENCE WHERE GROUP_ID=@group_id AND EMR_FETAURE-ID=48)
select 1 as status
else
select 0 as status

GO


Madhivanan

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

Kristen
Test

United Kingdom
22403 Posts

Posted - 01/27/2010 :  11:34:46  Show Profile  Reply with Quote
Although you don't really want all those columns selected if its just an EXIST test.
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22755 Posts

Posted - 01/28/2010 :  00:12:07  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
quote:
Originally posted by Kristen

Although you don't really want all those columns selected if its just an EXIST test.


Yes but I think it doesn't matter when using exists

Madhivanan

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

Kristen
Test

United Kingdom
22403 Posts

Posted - 01/28/2010 :  02:59:54  Show Profile  Reply with Quote
Oh, OK. Interesting point.
Go to Top of Page

rajasekhar857
Constraint Violating Yak Guru

396 Posts

Posted - 02/08/2010 :  04:01:04  Show Profile  Reply with Quote
yes i got it.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 02/08/2010 :  04:35:21  Show Profile  Reply with Quote
also see
http://www.sqlteam.com/article/stored-procedures-returning-data
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.09 seconds. Powered By: Snitz Forums 2000