Please check my current stored procedure.
USE [CastingDatabase]
GO
/****** Object: StoredProcedure [dbo].[Searching_Talents] Script Date: 11/11/2015 1:41:19 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[Searching_Talents]
@name nvarchar(100),
@age_from nvarchar(10),
@age_to nvarchar(10)
AS
BEGIN
SELECT *
FROM [dbo].[Talents]
WHERE(
((@name is null) or (@name='') or ([dbo].[Talents].[Name] LIKE '%'+@name+'%'))
AND
(((@age_to is null) or (@age_to='') or (DATEDIFF(YEAR,Talents.DOB,GETDATE()) IN
(
SELECT CAST (Item as int) FROM dbo.SplitString(@age_to,',')
)
))
)
)
ORDER BY Name
END
I want to add some if_else condition statements in second where clause.
How can I add?
I want to add like this
AND(if(@age_from is null){---- my codes ----})
P.S. I am a newbie in stored procedure. Please help me.