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. SQL and Joining in sql server2005

SQL and Joining in sql server2005

Scheduled Pinned Locked Moved Database
databasesql-serversysadmintoolshelp
4 Posts 4 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 two tables in sql server one is Emp and another is FieldsInfo. both table structure look like below CREATE TABLE [dbo].[Emp]( [ID] [int] NOT NULL, [EmpName] [varchar](50) NULL, [Sal] [nchar](10) NULL, ) CREATE TABLE [dbo].[FieldsInfo]( [TableName] [varchar](max) NULL, [FieldName] [varchar](max) NULL, [Description] [varchar](max) NULL ) now i want to join both the table such way that sql should show data from emp table but field name will be shown from FieldsInfo table according to the relation. i mean Employee ID will be shown as Field name instead of ID and Salary will be shown as field name instead of Sal but value will be just like emp table. i am not being able to generate this type of output after joining. so please help with right sql script. thanks

    tbhattacharjee

    D P 2 Replies Last reply
    0
    • T Tridip Bhattacharjee

      suppose i have two tables in sql server one is Emp and another is FieldsInfo. both table structure look like below CREATE TABLE [dbo].[Emp]( [ID] [int] NOT NULL, [EmpName] [varchar](50) NULL, [Sal] [nchar](10) NULL, ) CREATE TABLE [dbo].[FieldsInfo]( [TableName] [varchar](max) NULL, [FieldName] [varchar](max) NULL, [Description] [varchar](max) NULL ) now i want to join both the table such way that sql should show data from emp table but field name will be shown from FieldsInfo table according to the relation. i mean Employee ID will be shown as Field name instead of ID and Salary will be shown as field name instead of Sal but value will be just like emp table. i am not being able to generate this type of output after joining. so please help with right sql script. thanks

      tbhattacharjee

      D Offline
      D Offline
      dasblinkenlight
      wrote on last edited by
      #2

      You need to use pivot[^].

      M 1 Reply Last reply
      0
      • D dasblinkenlight

        You need to use pivot[^].

        M Offline
        M Offline
        Mahendra Vishwakarma
        wrote on last edited by
        #3

        I think Pvot will help you... HELLO GUY

        1 Reply Last reply
        0
        • T Tridip Bhattacharjee

          suppose i have two tables in sql server one is Emp and another is FieldsInfo. both table structure look like below CREATE TABLE [dbo].[Emp]( [ID] [int] NOT NULL, [EmpName] [varchar](50) NULL, [Sal] [nchar](10) NULL, ) CREATE TABLE [dbo].[FieldsInfo]( [TableName] [varchar](max) NULL, [FieldName] [varchar](max) NULL, [Description] [varchar](max) NULL ) now i want to join both the table such way that sql should show data from emp table but field name will be shown from FieldsInfo table according to the relation. i mean Employee ID will be shown as Field name instead of ID and Salary will be shown as field name instead of Sal but value will be just like emp table. i am not being able to generate this type of output after joining. so please help with right sql script. thanks

          tbhattacharjee

          P Offline
          P Offline
          Pravin Patil Mumbai
          wrote on last edited by
          #4

          Pivot is a new relational operator introduced in SQL 2005. You can use it to achieve the result. Refer http://msdn.microsoft.com/en-us/library/ms177410.aspx for more information

          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