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 6209381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:58:28+00:00 2026-05-24T05:58:28+00:00

I write the following stored procedure in sql server 2008 i am getting the

  • 0

I write the following stored procedure in sql server 2008 i am getting the error as i mentioned i don’t know why so can any one resolve this

create PROCEDURE dbo.uspTest1
as
    declare @cnt int;
    declare @cnt1 int;
    declare @cnt2 int;

     set @cnt=(SELECT COUNT(EmpID) AS Expr1 FROM tblTest WHERE (FedTaxID = '888888888') AND (TaxTypeCode = 'TX02'))

set @cnt1=(SELECT COUNT(EmpID) AS Expr1 FROM tblTest
WHERE(FedTaxID = '888888888') AND (TaxTypeCode = 'TX03'))
set @cnt2=(SELECT 
    TaxTypeCode, SUM(Amount) 
FROM 
    tblTest 
WHERE
    FedTaxID = '888888888'
    AND TaxTypeCode IN ('TX02', 'TX03')
GROUP BY
    TaxTypeCode)

This is the another one i tried this is also giving an error for me

create PROCEDURE dbo.uspTest1
as
    declare @cnt int;
    declare @cnt1 int;
    declare @cnt2 int;

     set @cnt=(SELECT     COUNT(EmpID) AS Expr1
FROM         tblTest
WHERE     (FedTaxID = '888888888') AND (TaxTypeCode = 'TX02'))

set @cnt1=(SELECT     COUNT(EmpID) AS Expr1
FROM         tblTest
WHERE     (FedTaxID = '888888888') AND (TaxTypeCode = 'TX03'))

set @cnt2=(SELECT  SUM(Txallt) as txnntot
  FROM (SELECT CASE WHEN  TaxTypeCode = 'tx02' THEN Amount else 0 END as tx02t,
               CASE WHEN  TaxTypeCode = 'tx03' THEN Amount else 0 END as tx03t,
               Amount as txallt
        FROM tbltest
        WHERE FedTaxID = '888888888'
       ))
GROUP BY FedTaxId

This is giving an error as Incorrect Syntax near ')'

So can any one tell what’s wrong i am doing

  • 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-24T05:58:29+00:00Added an answer on May 24, 2026 at 5:58 am

    Simply take out the TaxTypeCode in the first one

    set @cnt2=(SELECT 
        SUM(Amount) 
    FROM 
        tblTest 
    WHERE
        FedTaxID = '888888888'
        AND TaxTypeCode IN ('TX02', 'TX03')
    GROUP BY
        TaxTypeCode)
    

    However SUM(Amount)..GROUP BY will return multiple rows but you are trying to assign to one variable: one row in the result will be picked arbitrarily for @cnt2

    Do you need GROUP BY?

    If not, you can make this a lot simpler:

    SELECT
       @cnt = COUNT(CASE TaxTypeCode = 'TX02' THEN EmpID ELSE NULL END),
       @cnt1 = COUNT(CASE TaxTypeCode = 'TX03' THEN EmpID ELSE NULL END),
       @cnt2 = SUM(Amount)
    FROM
       tblTest
    WHERE
       FedTaxID = '888888888'
       AND
       TaxTypeCode IN ('TX02', 'TX03')
    

    Otherwise, add sample data and clear description of what you are trying to do…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to write SQL Server Stored Procedure which to be strongly
I'm trying to write a stored procedure [SQL 2008] with a dynamic, auto incrementing
Question How do I write a T-SQL Stored Procedure that lets me select percentages
I am using a Microsoft SQL Server 2005 stored procedure to post records in
I'm looking to write a C# SQL Server wrapper to call some stored procedures.
I'm trying to pass Japanese characters to a stored procedure in SQL Server. The
I have written the following piece of code ( sql clr stored procedure )
I need to run a stored procedure on SQL Server, using LINQ, and throw
How can I write the following code quickly in emacs? \newcommand{\cA}{\mathcal A} \newcommand{\cB}{\mathcal B}
How can you write the following statement in the given languages? a(0) = 1

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.