Categories
Database Development

File is getting generated into folder, But not a csv file

For the below SP, normal text file is getting generated instead of csv file.

ALTER PROCEDURE [dbo].[GenerateCDR_Test]
AS
BEGIN
DECLARE @FileName varchar(50),

@bcpCommand varchar(2000)

SET @FileName = ‘C:\TransactionsData’ + (‘Tansactions_’+ (CONVERT(VARCHAR, GETDATE(), 112) + ‘‘ + CAST(DATEPART(HOUR, GETDATE()) AS VARCHAR) + ‘‘ + CAST(DATEPART(MINUTE,GETDATE()) AS VARCHAR) + ‘_’ + CAST(DATEPART(SECOND, GETDATE()) AS VARCHAR)) + ‘.csv’);

SET @bcpCommand = ‘BCP ‘+’"SELECT * FROM [LinkVisaCard].[dbo].[CDRGeneration]"’ +’ queryout ‘

SET @bcpCommand = @bcpCommand + @FileName + ‘ -U abc -P password -w’

EXEC master..xp_cmdshell @bcpCommand
END

Leave a Reply

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