Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4126296
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:58:57+00:00 2026-05-20T23:58:57+00:00

I am using SSRS 2008 and i have a stored proc which currently uses

  • 0

I am using SSRS 2008 and i have a stored proc which currently uses cursors to delete and add data, but even after I convert this to select queries, I am getting error:

Msg 102, Level 15, State 1, Line 39
Incorrect syntax near ‘)’.

Here was the original Cursor which worked:

OPEN PARTS
FETCH PARTS INTO    @PART_NUM,
@PART_DESC
SET @PARTS_FETCH = @@FETCH_STATUS
WHILE @PARTS_FETCH = 0 BEGIN
SET @THE_DATE = dateadd("yy", -1, dateadd("m", -1, getdate()))
SET @END_DATE = DATEADD(ms, -5, DATEADD(mm, DATEDIFF(m, 0, getdate()) + 1, 0))

-- Get PL for part number 
Delete from @tbl_PL

Insert @tbl_PL 
SELECT FRUD.tblXref.product_code FROM FRUD.tblfieldOrderablePart INNER JOIN
FRUD.MAX_APPROVED ON FRUD.tblfieldOrderablePart.fop_no = FRUD.MAX_APPROVED.fop_no AND 
FRUD.tblfieldOrderablePart.fop_revision = FRUD.MAX_APPROVED.MaxOffop_revision INNER JOIN
FRUD.tblXref ON FRUD.MAX_APPROVED.fop_no = FRUD.tblXref.fop_no AND 
FRUD.MAX_APPROVED.MaxOffop_revision = FRUD.tblXref.fop_revision
WHERE (dbo.FORMAT_PART(FRUD.tblfieldOrderablePart.fop_no) = dbo.FORMAT_PART(@PART_NUM))
-- End Get PL

WHILE @THE_DATE <= @END_DATE BEGIN
SET @THE_DATE = DATEADD(ms, -5, DATEADD(mm, DATEDIFF(m, 0, @THE_DATE) + 1, 0))
-- Get census using PL          
SELECT @ALL_TOTAL = SUM(TheSum) FROM (SELECT CAST(RELIABILITY.Census.Census AS DECIMAL(9,2)) AS TheSum, (CONVERT(datetime, LEFT(CONVERT(char, Period), 4) + '-' + RIGHT(Period, 2) + '-1', 102)) as ThePeriod
FROM RELIABILITY.Census
WHERE RELIABILITY.Census.PL In (Select distinct * FROM @tbl_PL)
AND (CONVERT(datetime, LEFT(CONVERT(char, Period), 4) + '-' + RIGHT(Period, 2) + '-1', 102) >=
DATEADD(mm, DATEDIFF(mm, 0, @THE_DATE) - 5, 0)) AND (CONVERT(datetime, LEFT(CONVERT(char, Period), 4)
+ '-' + RIGHT(Period, 2) + '-1', 102) <= @THE_DATE)                         UNION ALL                           SELECT     CAST(Census AS DECIMAL(9,2)) AS TheSum, Period                           FROM         [MANUAL].SMARTSOLVE_CENSUS                         WHERE     (Period >= DATEADD(mm, DATEDIFF(mm, 0, @THE_DATE) - 5, 0) AND Period <= @THE_DATE) AND (PL In (Select distinct * FROM @tbl_PL)))A 

And here is my conversion to Select:

DECLARE @THE_DATE datetime,
        @END_DATE datetime,
        @THE_GOAL decimal(18,2),
        @PART_NUM nvarchar(50),
        @UNCHANGED_PART_NUM nvarchar(50),
        @PART_DESC varchar(35),
        @PARTS_FETCH int,
        @NUM_FAILED int,
        @AVG_CENSUS decimal(18,2),
        @PL_VAR nvarchar(50),   
        @PL_FETCH int,
        @PL_TOTAL decimal(9,2),
        @ALL_TOTAL decimal(9,2)

--WHILE @PARTS_FETCH = 0 BEGIN
    SET @THE_DATE = dateadd("yy", -1, dateadd("m", -1, getdate()))
    SET @END_DATE = DATEADD(ms, -5, DATEADD(mm, DATEDIFF(m, 0, getdate()) + 1, 0))  
    --WHILE @THE_DATE <= @END_DATE BEGIN
SET @THE_DATE = DATEADD(ms, -5, DATEADD(mm, DATEDIFF(m, 0, @THE_DATE) + 1, 0))
-- Get census using PL

SELECT @ALL_TOTAL = SUM(TheSum) FROM 
(SELECT CAST(RELIABILITY.Census.Census AS DECIMAL(9,2)) AS TheSum 
from RELIABILITY.Census
WHERE RELIABILITY.Census.PL In (Select distinct * FROM #tbl_PL) 
AND (CONVERT(datetime, LEFT(CONVERT(char, Period), 4) + '-' + RIGHT(Period, 2) + '-1', 102) >=  
DATEADD(mm, DATEDIFF(mm, 0, @THE_DATE) - 5, 0)) AND (CONVERT(datetime, LEFT(CONVERT(char, Period), 4)+ '-' + RIGHT(Period, 2) + '-1', 102) <= @THE_DATE)                    
UNION ALL
SELECT     CAST(Census AS DECIMAL(9,2)) AS TheSum, Period           
FROM         [MANUAL].SMARTSOLVE_CENSUS                 
WHERE     (Period >= DATEADD(mm, DATEDIFF(mm, 0, @THE_DATE) - 5, 0) AND Period <= @THE_DATE) AND (PL In (Select distinct * FROM #tbl_PL))
))A
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T23:58:57+00:00Added an answer on May 20, 2026 at 11:58 pm

    As Joel and Lamak pointed out you have an extra ) This is actually really easy to find if you use something like Instant SQL formatter This will give the error

    )(11,3) expected token:Unknown
    )(11,3) expected token: 
    

    It also formats the SQL as below which makes it a little easier to follow.

    SELECT @ALL_TOTAL = SUM(thesum) 
    FROM   (SELECT CAST(reliability.census.census AS DECIMAL(9, 2)) AS thesum 
            FROM   reliability.census 
            WHERE  reliability.census.pl IN (SELECT DISTINCT * 
                                             FROM   #tbl_pl) 
                   AND ( CONVERT(DATETIME, LEFT(CONVERT(CHAR, period), 4) + '-' + 
                         RIGHT( 
                         period, 2) 
                         + 
                         '-1' 
                         , 102) >= Dateadd(mm, Datediff(mm, 0, @THE_DATE) - 5, 0) ) 
                   AND ( CONVERT(DATETIME, LEFT(CONVERT(CHAR, period), 4)+ '-' + 
                         RIGHT( 
                         period, 2) + 
                         '-1', 
                         102) <= @THE_DATE ) 
            UNION ALL 
            SELECT CAST(census AS DECIMAL(9, 2)) AS thesum, 
                   period 
            FROM   [MANUAL].smartsolve_census 
            WHERE  ( period >= Dateadd(mm, Datediff(mm, 0, @THE_DATE) - 5, 0) 
                     AND period <= @THE_DATE ) 
                   AND ( pl IN (SELECT DISTINCT * 
                                FROM   #tbl_pl) ))a 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to access list data using SSRS 2008. I have created an XML
I am developing a stored proc for an SSRS 2008 report, but I want
I have developed reports using SSRS 2008 R2 but now need to deploy to
I'm using SSRS 2008 (NOT R2) I have a report deployed to a dev
I have a report in SSRS 2008 that shows data aggregated from four levels
I have a simple bar chart in an SSRS 2008 R2 report which is
I'm using SSRS 2008 and I have a financial report. I would like the
In SSRS Report Server (SQL Server 2008 R2), I have a shared data source
Please look at this ss I am using SSRS 2008 + pulling data from
I have built a report using Report Builder 3.0 (that uses SQL Server 2008

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.