I'm actually trying to get the data from a table but I wanted that "And/Or" changes based on the table. I'm using SQL Server.
I'm into something like this:
DECLARE @TURNOS TABLE (ID INT IDENTITY(1, 1),
INITURNO INT,
ENDTURNO INT,
ANDOR VARCHAR(3)
);
INSERT INTO @TURNOS
VALUES (23, 7, 'OR'), (7, 15, 'AND'), (15, 23, 'AND')
And I'm trying to do something like this:
WHILE (@count <= (SELECT COUNT(ID) FROM @TURNOS))
BEGIN
SET @initurno = SELECT INITURNO FROM @TURNOS WHERE ID = @count
SET @endturno = SELECT ENDTURNO FROM @TURNOS WHERE ID = @count
SET @andor = SELECT ANDOR FROM @TURNOS WHERE ID = @count
INSERT INTO @AnotherTable
SELECT *
FROM dbo.TableA
WHERE DATES BETWEEN DATEPART(hh, DATES) >= @initurno @andor DATEPART(hh, DATES) < @enturno
END
Is there any way that I can use a variable And/Or like I tried with @andor
?
Thanks in advance :)