Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQL brain freeze
Message
De
23/02/2017 11:11:52
 
 
À
Tous
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
SQL brain freeze
Divers
Thread ID:
01648427
Message ID:
01648427
Vues:
49
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.
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform