/*
This example is connecting to a Lab Test table with LabTest = Name of Lab Test,
LabDate = Date that the LabTest was Performed
CREATE TABLE [dbo].[LabTests](
[LabTestId] [int] IDENTITY(1,1) NOT NULL,
[LabDate] [datetime] NULL,
[LabTime] [varchar](50) NULL,
[LabTest] [varchar](50) NOT NULL,
[LabResult] [varchar](50) NULL,
[LabUnits] [varchar](50) NULL,
[LabNormalRange] [varchar](50) NULL,
[LabNotes] [varchar](1000) NULL
) ON [PRIMARY]
*/
--Declaring variable name and type
DECLARE @LabTest varchar(100)
DECLARE @StartDate datetime
--Setting the Variable value
SET @LabTest = 'HGB'
SET @StartDate = '9/23/2013'
--Utilizing variable within the WHERE clause
SELECT LabTest, LabName, LabResult, LabUnits
FROM LabTests
WHERE LabTest = @LabTest and LabDate >= @StartDate
This example is connecting to a Lab Test table with LabTest = Name of Lab Test,
LabDate = Date that the LabTest was Performed
CREATE TABLE [dbo].[LabTests](
[LabTestId] [int] IDENTITY(1,1) NOT NULL,
[LabDate] [datetime] NULL,
[LabTime] [varchar](50) NULL,
[LabTest] [varchar](50) NOT NULL,
[LabResult] [varchar](50) NULL,
[LabUnits] [varchar](50) NULL,
[LabNormalRange] [varchar](50) NULL,
[LabNotes] [varchar](1000) NULL
) ON [PRIMARY]
*/
--Declaring variable name and type
DECLARE @LabTest varchar(100)
DECLARE @StartDate datetime
--Setting the Variable value
SET @LabTest = 'HGB'
SET @StartDate = '9/23/2013'
--Utilizing variable within the WHERE clause
SELECT LabTest, LabName, LabResult, LabUnits
FROM LabTests
WHERE LabTest = @LabTest and LabDate >= @StartDate