Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Converting Rows into columns
Message
De
04/09/2012 11:44:13
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
Application:
Web
Divers
Thread ID:
01552284
Message ID:
01552327
Vues:
38
>>Hiii Thanks for Support. I wants to show fee status which is greater than 0
>>suppose i have two students and output of two students is coming like
>>
>> Emty # Dollar
>> St1 0 0 450
>> St2 0 230 0
>>
>>
>>Now St1 has amount greater than 0 in dollar than Dollar Fee status should come with amount 450 same as for St2 # staus with amount 230 shold come
>
>As I just answered in MSDN, get rid of FeeStatus column in the list of fields and GROUP BY and the code should work fine as is now since you're using MAX. You can alternatively use SUM, in your case it will be the same.
********************************************************************************************

Hi Naomi my Final query is this but how to correct it means how to show according to my Requiremnt i don't know I tried alot but not getting result

DECLARE @SQL NVARCHAR(max)

SELECT @SQL = (
SELECT ', COALESCE(MAX(case when FeeName = ' + quotename(FeeName, '''') +
' then case when FeeName=''Pending'' and BillNumber=0 then 0 else Amount end end),0) AS ' + quotename(FeeName) + ' ,FeeStatus+'' ''+CAST(COALESCE(MAX(case when FeeName = ' + quotename(FeeName, '''') +
' then case when FeeName=''Pending'' and BillNumber=0 then 0 else Amount end end),0)as nvarchar(max)) AS ' + quotename(FeeName+'1') + '
, COALESCE(MAX(case when FeeName = ' + quotename(FeeName, '''') +
' then Concession end),0) AS [Concession]'
FROM (
SELECT DISTINCT FeeName,FeeTypeId
FROM Sample_Table1
) S
ORDER BY FeeTypeId
FOR XML PATH('')
,type
).value('.', 'nvarchar(max)')



SELECT @SQL = 'SELECT EnrolmentId, StudentId, [Name],Feestatus ' + @SQL + ', MAX(BillNumber) As BillNumber,
SUM((case when FeeStatus=''$'' or FeeName = ''CREDIT'' THEN -1 ELSE 1 END) * Amount) AS [Total Amount]
from Sample_Table1 where IsBlock!=1
GROUP BY EnrolmentId, StudentId, [Name],FeeStatus
ORDER BY [Name]'

PRINT @SQL

EXECUTE (@SQL)
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform