SQL Server crosstab query case_mssql

Source: Internet
Author: User
Tags crosstab

The code looks like this:

The table Landundertake structure looks like this:

The table appraiser structure looks like this:

Access code:

Copy Code code as follows:

TRANSFORM A (Landundertake.valuerid) as Valuerid
SELECT Appraiser.quarterid, Landundertake.landcode
From Landundertake INNER JOIN appraiser on (landundertake. Valuerid = Appraiser.valuerid) and (landundertake. Quarterid = Appraiser.quarterid)
GROUP by Appraiser.quarterid, Landundertake. Landcode
PIVOT Landundertake. Valuergrade;

SQL Server Code:
Copy Code code as follows:

Select Dbo.appraiser.quarterid,dbo.landundertake.landcode,case Dbo.landUndertake.appraiserGrade when ' AppraiserID1 ' then Dbo.landundertake.appraiserID else null end as Appraiserid,case dbo.landUndertake.appraiserGrade When ' appraiserID2 ' then Dbo.landundertake.appraiserID else null end as AppraiserID1
FROM dbo. Landundertake INNER JOIN
Dbo. Appraiser on dbo. Landundertake.quarterid=dbo.appraiser.quarterid and Dbo.landundertake.appraiserid=dbo. Appraiser.appraiserid
Group by Dbo.appraiser.quarterid,dbo.landundertake.landcode,dbo.landundertake.appraisergrade, Dbo.landundertake.appraiserID

The crosstab query results are as follows:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.