Category Archives: SQL Server
How to concatenate row data by comma in sql?
How to concatenate row data by “,” in sql? DECLARE @Account_Num VARCHAR(7500) = ” CREATE TABLE #tempData ( AccountNo VARCHAR(20) ) INSERT INTO #tempData SELECT ‘123456’ UNION SELECT ‘89105’ UNION SELECT ‘32587’ UNION SELECT ‘98587’ SELECT @Account_Num += COALESCE(‘,’, @Account_Num) + AccountNo FROM #tempData SET @Account_Num = SUBSTRING(@Account_Num, 2, LEN(@Account_Num)) SELECT @Account_Num Result: 123456,89105,32587,98587
how to copy directory using sql server
DECLARE @Query VARCHAR(8000) SET @Query = ‘xcopy “{Source Directory Path}\*.*” “{Destination Directory Path}\” /e /i /h /y ‘ PRINT @Query EXEC master.dbo.xp_cmdshell @Query Where “*.*” Copy all directory and file in source path. “/e” Copies directories and sub directories, including empty ones. Same as /S /E. May be used to modify /T. “/i” If destination does not […]
difference between union and union all
UNION Union gives distinct records or entries from all table. SELECT dbA, dbB FROM tbl1 UNION SELECT dbA, dbB FROM tbl2 UNION ALL Union All gives all records from tbl1 and tbl2 SELECT dbA, dbB FROM tbl1 UNION ALL SELECT dbA, dbB FROM tbl2