SQL Variable TABLE quick setup and insert

DECLARE @SampleDataTable TABLE (    ID INT IDENTITY(1,1) PRIMARY KEY,    Date SMALLDATETIME,     EndDate SMALLDATETIME)INSERT INTO @SampleDataTable     SELECT '2011-03-01', NULL    UNION ALL    SELECT '2011-03-02', NULL    UNION ALL    SELECT '2011-03-03', NULL    UNION ALL    SELECT '2011-03-04', NULL    UNION ALL    SELECT '2011-03-05', NULL    SELECT * FROM @SampleDataTable

OR

DECLARE @SampleDataTable TABLE (    ID INT IDENTITY(1,1) PRIMARY KEY,    Date SMALLDATETIME,     EndDate SMALLDATETIME)INSERT INTO @SampleDataTable (     Date, EndDate )(    SELECT '2011-03-01', NULL    UNION ALL    SELECT '2011-03-02', NULL    UNION ALL    SELECT '2011-03-03', NULL    UNION ALL    SELECT '2011-03-04', NULL    UNION ALL    SELECT '2011-03-05', NULL)SELECT * FROM @SampleDataTable

Leave a Reply

Your email address will not be published. Required fields are marked *