Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL brain freeze
Message
From
23/02/2017 11:11:52
 
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
SQL brain freeze
Miscellaneous
Thread ID:
01648427
Message ID:
01648427
Views:
50
9,999 times out of 10,000 there will be a row.
How can I avoid the second query here?
CREATE FUNCTION dbo.GetStoreNameAndAddress           -- function name
(@storecode CHAR(11))                     -- input parameter name and data type
RETURNS CHAR(50)                          -- return parameter data type
AS
BEGIN                                -- begin body definition
DECLARE @StoreNameAndAddress CHAR(50)
IF EXISTS (select * FROM store where LEFT(storecode,11) = @storecode)
   SELECT @StoreNameAndAddress = ( select RTRIM(store_name) + ' ' + RTRIM(f_address) from store where LEFT(storecode,11) = @storecode)
ELSE
     SELECT @StoreNameAndAddress = 'Unknown Store'
RETURN @StoreNameAndAddress
END
GO
Anyone who does not go overboard- deserves to.
Malcolm Forbes, Sr.
Next
Reply
Map
View

Click here to load this message in the networking platform