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 |
shapper
Constraint Violating Yak Guru
450 Posts |
Posted - 2006-12-03 : 21:00:56
|
Hello,I created a stored procedure which selects a value according to ContentId.I know that will be only one value returned or none.So if a record is found I want to return the string contained in ContentHtml.Else I want to return the string "NotFound"Could somebody help me out with this?Here is my present stored procedure:-- Specifies the SQL-92 equals compliant behaviorSET ANSI_NULLS ONGO-- Specifies the SQL-92 quotation mark rules SET QUOTED_IDENTIFIER ONGO-- Alter procedureALTER PROCEDURE [dbo].[by27_Content_GetContent] -- Define the procedure parameters @ContentName NVARCHAR(100), @ContentCulture NVARCHAR(5)AS-- Prevent extra result sets from interfering with SELECT statements.SET NOCOUNT ON;-- Declare and define ContentIdDECLARE @ContentId UNIQUEIDENTIFIER;SELECT @ContentId = ContentId FROM dbo.by27_Content WHERE ContentName = @ContentName-- Check if ContentId is Not NullIF @ContentId IS NOT NULL BEGIN -- Select localized content from by27_ContentLocalized SELECT dbo.by27_ContentLocalized.ContentHtml FROM dbo.by27_Content INNER JOIN dbo.by27_ContentLocalized ON dbo.by27_Content.ContentId = dbo.by27_ContentLocalized.ContentId WHERE (dbo.by27_ContentLocalized.ContentCulture = @ContentCulture AND dbo.by27_Content.ContentName = @ContentName); END-- Create procedureGOThanks,Miguel |
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2006-12-03 : 23:35:55
|
How about this?IF EXISTS(SELECT * FROM dbo.by27_Content WHERE ContentName = @ContentName)SELECT dbo.by27_ContentLocalized.ContentHtmlFROM dbo.by27_ContentINNER JOIN dbo.by27_ContentLocalizedON dbo.by27_Content.ContentId = dbo.by27_ContentLocalized.ContentIdWHERE dbo.by27_ContentLocalized.ContentCulture = @ContentCulture AND dbo.by27_Content.ContentName = @ContentNameELSESELECT 'NotFound' as ContentHtml Harsh AthalyeIndia."Nothing is Impossible" |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-12-04 : 09:33:48
|
>>So if a record is found I want to return the string contained in ContentHtml.Else I want to return the string "NotFound"If you use front end application, you can check there alsoIf Rs.eof then--No recordsMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|