Hi Guys,
I am a new programmer and I was given a code to fix....I just would like to know what does this portion of code do (i.e the write flag part):
Description: Exports Style info to flat file.
CREATE PROCEDURE dbo.msp_EIExportStyleCornell
@intSessionNo int
, @intType int -- 0 = Write output file; 1 = SELECT for output
, @intExportCount int = NULL
AS
SET NOCOUNT ON
DECLARE @chvCmdLine varchar(1024)
, @chvPath varchar(512)
, @chvDateStamp varchar(8)
, @chvFileName varchar(50)
, @intIDENT int
, @chvFileWrite varchar(5)
, @intOriginalCount int
, @chvHeaderValue varchar(5)
, @dteDateValue smalldatetime
-- FILE WRITE FLAG
IF (@intExportCount = 0 OR @intExportCount IS NULL)
BEGIN
SET @chvFileWrite = ' > '
SET @chvHeaderValue = '-1'
SET @intOriginalCount = @intExportCount
END
ELSE
BEGIN
SET @chvFileWrite = ' >> '
SET @chvHeaderValue = '-1'
SET @intOriginalCount = @intExportCount
CREATE TABLE #tmp_Count([intCount] [int])
INSERT INTO #tmp_Count
EXEC(' SELECT MAX(Interface_Out_Id)
FROM(SELECT TOP ' + @intExportCount + ' Interface_Out_Id
FROM Interface_Out
WHERE SessionNo = ' + @intSessionNo + ') TMP ')
SELECT @intExportCount = intCount FROM #tmp_Count
END
IF @intType = 0
BEGIN
-- FILE WRITE FLAG
IF (@intExportCount = 0 OR @intExportCount IS NULL)
BEGIN
-- CREATE FILE NAME
SET @chvDateStamp = RIGHT(DATEPART(yy, getdate()), 2) + RIGHT('0' + CAST(DATEPART(mm, getdate()) as varchar(2)), 2)
+ RIGHT('0' + CAST(DATEPART(dd, getdate()) as varchar(2)), 2)
SELECT @chvFileName = 'style_upc_' + RTRIM(LTRIM(country_cd)) + '_' + @chvDateStamp + '.txt' FROM _Constant
SET @dteDateValue = CONVERT(smalldatetime, CONVERT(varchar(50), DATEPART(mm, getdate()) + '-' + DATEPART(dd, getdate()) + '-' + DATEPART(yy, getdate()) ) )
I am a new programmer and I was given a code to fix....I just would like to know what does this portion of code do (i.e the write flag part):
Description: Exports Style info to flat file.
CREATE PROCEDURE dbo.msp_EIExportStyleCornell
@intSessionNo int
, @intType int -- 0 = Write output file; 1 = SELECT for output
, @intExportCount int = NULL
AS
SET NOCOUNT ON
DECLARE @chvCmdLine varchar(1024)
, @chvPath varchar(512)
, @chvDateStamp varchar(8)
, @chvFileName varchar(50)
, @intIDENT int
, @chvFileWrite varchar(5)
, @intOriginalCount int
, @chvHeaderValue varchar(5)
, @dteDateValue smalldatetime
-- FILE WRITE FLAG
IF (@intExportCount = 0 OR @intExportCount IS NULL)
BEGIN
SET @chvFileWrite = ' > '
SET @chvHeaderValue = '-1'
SET @intOriginalCount = @intExportCount
END
ELSE
BEGIN
SET @chvFileWrite = ' >> '
SET @chvHeaderValue = '-1'
SET @intOriginalCount = @intExportCount
CREATE TABLE #tmp_Count([intCount] [int])
INSERT INTO #tmp_Count
EXEC(' SELECT MAX(Interface_Out_Id)
FROM(SELECT TOP ' + @intExportCount + ' Interface_Out_Id
FROM Interface_Out
WHERE SessionNo = ' + @intSessionNo + ') TMP ')
SELECT @intExportCount = intCount FROM #tmp_Count
END
IF @intType = 0
BEGIN
-- FILE WRITE FLAG
IF (@intExportCount = 0 OR @intExportCount IS NULL)
BEGIN
-- CREATE FILE NAME
SET @chvDateStamp = RIGHT(DATEPART(yy, getdate()), 2) + RIGHT('0' + CAST(DATEPART(mm, getdate()) as varchar(2)), 2)
+ RIGHT('0' + CAST(DATEPART(dd, getdate()) as varchar(2)), 2)
SELECT @chvFileName = 'style_upc_' + RTRIM(LTRIM(country_cd)) + '_' + @chvDateStamp + '.txt' FROM _Constant
SET @dteDateValue = CONVERT(smalldatetime, CONVERT(varchar(50), DATEPART(mm, getdate()) + '-' + DATEPART(dd, getdate()) + '-' + DATEPART(yy, getdate()) ) )