Se il valore del parametro non è fisso o il vostro valore può essere nullo basata su attività si può prova il seguente approccio.
DECLARE @DrugClassstring VARCHAR(MAX);
SET @DrugClassstring = 'C3,C2'; -- You can pass null also
---------------------------------------------
IF @DrugClassstring IS NULL
SET @DrugClassstring = 'C3,C2,C4,C5,RX,OT'; -- If null you can set your all conditional case that will return for all
SELECT dn.drugclass_FK , dn.cdrugname
FROM drugname AS dn
INNER JOIN dbo.SplitString(@DrugClassstring, ',') class ON dn.drugclass_FK = class.[Name] -- SplitString is a a function
funzione SplitString
SET ANSI_NULLS ON;
GO
SET QUOTED_IDENTIFIER ON;
GO
ALTER FUNCTION [dbo].[SplitString](@stringToSplit VARCHAR(MAX),
@delimeter CHAR(1) = ',')
RETURNS @returnList TABLE([Name] [NVARCHAR](500))
AS
BEGIN
--It's use in report sql, before any change concern to everyone
DECLARE @name NVARCHAR(255);
DECLARE @pos INT;
WHILE CHARINDEX(@delimeter, @stringToSplit) > 0
BEGIN
SELECT @pos = CHARINDEX(@delimeter, @stringToSplit);
SELECT @name = SUBSTRING(@stringToSplit, 1, @pos-1);
INSERT INTO @returnList
SELECT @name;
SELECT @stringToSplit = SUBSTRING(@stringToSplit, @pos+1, LEN(@stringToSplit)[email protected]);
END;
INSERT INTO @returnList
SELECT @stringToSplit;
RETURN;
END;
fonte
2016-09-09 10:34:08
Cosa c'è di sbagliato con OR? O hai una serie dinamica di condizioni? –
Cosa c'è che non va con gli OR? Il volume della digitazione? –
Ovviamente, ho usato OR in tempo reale. Ma voglio sapere se esiste un altro modo per sostituire OR – Madhu