Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Interesting Query.. I think

Author  Topic 

Da_Retina
Posting Yak Master

109 Posts

Posted - 2002-03-05 : 06:30:47
SELECT @AccountTotalId=AccountTotalId FROM GLR_AccountsTotals,GLR_PayrollGroups
Where GroupId=@GroupId AND GLR_AccountsTotals.AccountId=GLR_PayrollGroups.AccountId1 AND
ISNULL(Total1,-1)<>-1
If @@RowCount=1
Begin
-- First Total
SELECT @AccountTotalId=AccountTotalId, @ValueDb=Total1, @ValueCr = 0
FROM GLR_AccountsTotals,GLR_PayrollGroups
WHERE GroupId=@GroupId and GLR_AccountsTotals.AccountId=GLR_PayrollGroups.AccountId1

SELECT @SystemTransId=SystemId From GLR_Accounts,GLR_PayrollGroups
Where GroupId=@GroupId and GLR_Accounts.AccountId=GLR_PayrollGroups.AccountId1
End

ok..I need to REPEAT that block 14 times for every balded field I need to change the (1) to 2 ,3,4,...14
In other words I need to make the column name variable !!..Can I do that??..
Please HELP ME!
Salute Pals..

------------------
If I am to do it,
I will, and NOW ..

Nazim
A custom title

1408 Posts

Posted - 2002-03-05 : 07:35:31
You can use dynamic Sql.

Merkin has written a two part article on using Dynamic Sql
http://www.sqlteam.com/item.asp?ItemID=4619.


HTH

--------------------------------------------------------------
Go to Top of Page
   

- Advertisement -