Tuesday, July 25, 2017

SQL Generate Date from given date range



 WITH Dates AS (  
     SELECT  
      [Date] = CONVERT(DATETIME,'1-1-2017')  
     UNION ALL SELECT  
      [Date] = DATEADD(DAY, 1, [Date])  
     FROM  
      Dates  
     WHERE  
      Date < '12-31-2017'  
 ) SELECT [Date]  
 FROM Dates  
 OPTION (MAXRECURSION 1000)  



Friday, July 14, 2017

Run all SQL files from a folder



Run all SQL files from  a folder you can follow the process that will save your time for executing SQL script


Copy this code in a notepad file and change the Server, Database, Username And Password value as your self and save it as a .bat file. copy the file in your SQL script folder and run this bat file.

 REM  
  REM development environment only!!  
 REM  
 pause  
 for %%G in (*.sql) do sqlcmd /S "192.168.10.139\SQLEXPRESS" /d "VSSPORT_DEV" -U "atiour" -P "atiour" -i"%%G"  
 pause  
 REM  
  REM All Script Run Successfully  
 REM  




SQL Get all Index create script from Database

To get all script from database as a create new index into another database you can use the following --Get all Index Script SELECT...