Results 1 to 2 of 2

Thread: Help with T-sql

  1. #1
    Join Date
    Jul 2008
    Posts
    10

    Unanswered: Help with T-sql

    I am tryingto write a script that will extrct data into csv file.
    Currnetly getting an error at the end for )

    set ANSI_NULLS ON
    set QUOTED_IDENTIFIER ON
    go



    ALTER PROCEDURE [dbo].[SP_Send_Unsubscribed_Emails_Spring]
    (
    @lAgencyID INT
    ,@sRecipients varchar(250)
    )
    AS
    BEGIN


    SET NOCOUNT ON

    Declare @FromDate datetime
    Declare @ToDate datetime
    declare @ssubject varchar(200)
    --DECLARE @tableHTML NVARCHAR(MAX)




    -- get the 1st of last month
    if (datepart(month,getDate())-1) <> 0
    BEGIN
    set @FromDate = convert(datetime, convert(varchar,datepart(month,getDate())-1) + '/1/' + convert(varchar,datepart(year,getDate())))
    END
    ELSE
    BEGIN
    set @FromDate = '12/1/' + convert(varchar,datepart(year,getDate())-1)
    END

    -- get the 1st of this month
    set @ToDate = convert(datetime, convert(varchar,datepart(month,getDate())) + '/1/' + convert(varchar,datepart(year,getDate())))

    -- set the subject of the e-mail
    set @ssubject = (select upper(sName) from tCompanies where lid = @lAgencyID) + ' :Unsubscribed Candidates month beginning ' + convert(varchar,@FromDate)


    -- AS NVARCHAR(MAX) ) +
    (select count(distinct pd.lCandidateID)

    from tsm4.dbo.tprivatepool_deleted pd with (nolock)
    where pd.dtenteredon between @FromDate and @ToDate
    and pd.lAgencyID = @lAgencyID
    and lAlternativeID is not null
    and pd.lCandidateID not in (select lid from tsm4.dbo.tTransposedDeletes t with (nolock))

    ERROR
    Msg 102, Level 15, State 1, Procedure SP_Send_Unsubscribed_Emails_Spring, Line 47
    Incorrect syntax near ')'.

  2. #2
    Join Date
    Jan 2004
    Location
    In a large office with bad lighting
    Posts
    1,040
    try getting rid of the open parenthesis in front of the select that follows your commented out "AS NVARCHAR(MAX)).

    -- This is all just a Figment of my Imagination --

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •