SQL and Joining in sql server2005
-
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
-
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
-
I think Pvot will help you... HELLO GUY
-
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
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