In SQL Server, on .NET you can add together a SQL statement and therefor use either 'or' or 'and'.
I am stuck how to do this in a SQL Server stored procedure.
Question:
What is it called what you add together SQL statements? I have a feeling it starts with a 'c' concocations??
I believe I am close with the below code to having a 'variable' SQL?
Code:
BEGIN
SELECT *
FROM TblEmployee
WHERE
FirstName LIKE '%' + LTRIM(RTRIM((@sFirstName))) + '%'
or
Surname LIKE '%' + LTRIM(RTRIM((@sSurname ))) + '%'
and
IF (LTRIM(RTRIM((@sOfficeBase))) = 'xyz1234')
and OfficeBase = LTRIM(RTRIM((@sOfficeBase)))
ELSE
or
OfficeBase= LTRIM(RTRIM((@sOfficeBase)))
END
There are simular queries such as If else in stored procedure sql server
But I have a feeling I searching for the 'wrong' question. Thanks in advance
ELSE OR/IF ANDare nonsensical, the format isIF/ELSE <condition> [OR/AND ...]perhaps you had better describe the logic you want in words as its hard to interpret what you have shown.