Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. How to write a SQL query to present values horizontally sql server 2005

How to write a SQL query to present values horizontally sql server 2005

Scheduled Pinned Locked Moved Database
databasequestionsql-serversysadmintutorial
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tridip Bhattacharjee
    wrote on last edited by
    #1

    Suppose I have one table called Jobs: CREATE TABLE [Jobs] ( [JOBID] [int] IDENTITY(1,1) NOT NULL, [PARTDESC] [nvarchar](64) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [OrderPlacedBy] [nvarchar](64) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, [SpecialistName] [nvarchar](64) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [Priority] [int] NOT NULL, [Symptoms] [ntext] COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [CustomerNotes] [ntext] COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [ShopNotes] [ntext] COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [JobType] [nvarchar](32) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [JobState] [nvarchar](32) COLLATE Latin1_General_CI_AS NULL, [JobAddedDate] [datetime] NOT NULL, [JobStartedDate] [datetime] NULL, [JobFinishedDate] [datetime] NULL, [JobShippedDate] [datetime] NULL, [RecievedDate] [datetime] NULL ) I want to see the specialist name and his jobs IDs horizontally. ANA 201,502,605,701,774 BEN 102,103,051 JEN 705,401,402,509,409,408 A specialist may have n jobs. Suppose specialist ANA has 10 jobs where BEN has 5 jobs. In this way I want to show specialist his jobs horizontally where the number of jobs may vary per specialist. How can I do this in SQL?

    tbhattacharjee

    J M P 3 Replies Last reply
    0
    • T Tridip Bhattacharjee

      Suppose I have one table called Jobs: CREATE TABLE [Jobs] ( [JOBID] [int] IDENTITY(1,1) NOT NULL, [PARTDESC] [nvarchar](64) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [OrderPlacedBy] [nvarchar](64) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, [SpecialistName] [nvarchar](64) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [Priority] [int] NOT NULL, [Symptoms] [ntext] COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [CustomerNotes] [ntext] COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [ShopNotes] [ntext] COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [JobType] [nvarchar](32) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [JobState] [nvarchar](32) COLLATE Latin1_General_CI_AS NULL, [JobAddedDate] [datetime] NOT NULL, [JobStartedDate] [datetime] NULL, [JobFinishedDate] [datetime] NULL, [JobShippedDate] [datetime] NULL, [RecievedDate] [datetime] NULL ) I want to see the specialist name and his jobs IDs horizontally. ANA 201,502,605,701,774 BEN 102,103,051 JEN 705,401,402,509,409,408 A specialist may have n jobs. Suppose specialist ANA has 10 jobs where BEN has 5 jobs. In this way I want to show specialist his jobs horizontally where the number of jobs may vary per specialist. How can I do this in SQL?

      tbhattacharjee

      J Offline
      J Offline
      Jorgen Andersson
      wrote on last edited by
      #2

      Make a search on Pivot[^].

      List of common misconceptions

      1 Reply Last reply
      0
      • T Tridip Bhattacharjee

        Suppose I have one table called Jobs: CREATE TABLE [Jobs] ( [JOBID] [int] IDENTITY(1,1) NOT NULL, [PARTDESC] [nvarchar](64) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [OrderPlacedBy] [nvarchar](64) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, [SpecialistName] [nvarchar](64) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [Priority] [int] NOT NULL, [Symptoms] [ntext] COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [CustomerNotes] [ntext] COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [ShopNotes] [ntext] COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [JobType] [nvarchar](32) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [JobState] [nvarchar](32) COLLATE Latin1_General_CI_AS NULL, [JobAddedDate] [datetime] NOT NULL, [JobStartedDate] [datetime] NULL, [JobFinishedDate] [datetime] NULL, [JobShippedDate] [datetime] NULL, [RecievedDate] [datetime] NULL ) I want to see the specialist name and his jobs IDs horizontally. ANA 201,502,605,701,774 BEN 102,103,051 JEN 705,401,402,509,409,408 A specialist may have n jobs. Suppose specialist ANA has 10 jobs where BEN has 5 jobs. In this way I want to show specialist his jobs horizontally where the number of jobs may vary per specialist. How can I do this in SQL?

        tbhattacharjee

        M Offline
        M Offline
        Mycroft Holmes
        wrote on last edited by
        #3

        There are some excellent articles [^]here on CP (blatant self promotion here)

        Never underestimate the power of human stupidity RAH

        W 1 Reply Last reply
        0
        • T Tridip Bhattacharjee

          Suppose I have one table called Jobs: CREATE TABLE [Jobs] ( [JOBID] [int] IDENTITY(1,1) NOT NULL, [PARTDESC] [nvarchar](64) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [OrderPlacedBy] [nvarchar](64) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, [SpecialistName] [nvarchar](64) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [Priority] [int] NOT NULL, [Symptoms] [ntext] COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [CustomerNotes] [ntext] COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [ShopNotes] [ntext] COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [JobType] [nvarchar](32) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [JobState] [nvarchar](32) COLLATE Latin1_General_CI_AS NULL, [JobAddedDate] [datetime] NOT NULL, [JobStartedDate] [datetime] NULL, [JobFinishedDate] [datetime] NULL, [JobShippedDate] [datetime] NULL, [RecievedDate] [datetime] NULL ) I want to see the specialist name and his jobs IDs horizontally. ANA 201,502,605,701,774 BEN 102,103,051 JEN 705,401,402,509,409,408 A specialist may have n jobs. Suppose specialist ANA has 10 jobs where BEN has 5 jobs. In this way I want to show specialist his jobs horizontally where the number of jobs may vary per specialist. How can I do this in SQL?

          tbhattacharjee

          P Offline
          P Offline
          PIEBALDconsult
          wrote on last edited by
          #4

          With Sql Server, you can write your own aggregate function[^]. And you spelled received wrong.

          1 Reply Last reply
          0
          • M Mycroft Holmes

            There are some excellent articles [^]here on CP (blatant self promotion here)

            Never underestimate the power of human stupidity RAH

            W Offline
            W Offline
            Wendelius
            wrote on last edited by
            #5

            Must say that you found an excellent article for this issue ! :)

            The need to optimize rises from a bad design.My articles[^]

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups