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
Simply take out the TaxTypeCode in the first one
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:
Otherwise, add sample data and clear description of what you are trying to do…