August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!
CREATE PROCEDURE [dbo].[pTest] ( @Start_Date_Format DATETIME= '2016-03-06', @End_Date_Format DATETIME= '2016-03-19' ) AS DECLARE @SQL NVARCHAR(4000) DECLARE @FinalSQL NVARCHAR(4000) SET @SQL='Select Zip, Sum(orig_qty) as orig_qty from stk_transfer inner join data_location dl1 on stk_transfer.desp_loc_id = dl1.id inner join data_location dl2 on stk_transfer.del_loc_id = dl2.id inner join address on dl2.address_id = address.id where received_date between '+ @Start_Date_Format + ' and ' +@End_Date_Format + ' and desp_loc_id = 101 and del_loc_id <> 8 Group by Zip' SET @FinalSQL = 'Select B.[GeoLocation],A.zip,A.orig_qty From OPENQUERY([MYSQLCYBERTILL], ' + '''' + @SQL + '''' + ') as A inner join [dbo].[PostcodeUKAll] as B on A.Zip = B.Postcode' PRINT @FinalSQL EXEC(@FinalSQL) GO
EXEC pTest @Start_Date_Format = '2016-05-01 00:00:00', @End_Date_Format = '2016-08-26 23:59:59'
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
Join the community of 500,000 technology professionals and ask your questions.