neditheg
Starting Member
3 Posts |
Posted - 2014-01-30 : 05:32:24
|
I have 3 tablesCREATE TABLE [dbo].[tblCRMA]( [ClientId] [int] IDENTITY(1,1) NOT NULL, [MCC_AgentId] [int] NULL, [MCC_ClientId] [int] NULL, [ImportSessionId] [int] NULL, [DateInserted] [datetime] NULL, [DateModified] [datetime] NOT NULL, [MCC_LastCall] [datetime] NULL, [MCC_LastCallCode] [int] NULL, [PdV_transanti_nel_periodo] [nvarchar](255) NULL, [TSR] [nvarchar](255) NULL, [Sales_Yes_No] [nvarchar](255) NULL, [Cluster] [nvarchar](255) NULL, [Next_Call] [nvarchar](255) NULL, [ATTIVI_AL_27_01] [nvarchar](255) NULL, [da_chiamare_per_taglio_da_5] [nvarchar](255) NULL, [da_chiamare_per_taglio_da_10] [nvarchar](255) NULL, [da_chiamare_per_taglio_da_20] [nvarchar](255) NULL, [da_chiamare_per_taglio_da_5e10] [nvarchar](255) NULL, [da_chiamare_per_taglio_da_10e20] [nvarchar](255) NULL, [da_chiamare_per_taglio_da_5e20] [nvarchar](255) NULL, [da_chiamare_per_tutti_i_tagli] [nvarchar](255) NULL, [ESITO] [nvarchar](2000) NULL, [MOTIVAZIONI_non_ordina_prod_carenti] [nvarchar](2000) NULL, [Note] [nvarchar](255) NULL)--------------------------------------------------------------CREATE TABLE [dbo].[tblCRMA_History]( [tblHistoryId] [int] IDENTITY(1,1) NOT NULL, [ClientId] [int] NOT NULL, [FieldId] [int] NOT NULL, [FieldName] [varchar](128) NULL, [FieldCrmColumn] [nvarchar](255) NULL, [ValueOld] [nvarchar](max) NULL, [ValueNew] [nvarchar](max) NULL, [DateUpdated] [datetime] NOT NULL, [UpdatedByUserId] [int] NULL)------------------CREATE TABLE [dbo].[agents]( [AGENTID] [int] NOT NULL DEFAULT ('-1'), [AGENTNAME] [varchar](255) NOT NULL DEFAULT (''), [AGENTPIN] [varchar](30) NOT NULL DEFAULT (''), [AGENTGROUP] [varchar](20) NULL DEFAULT (NULL), [NUMBERPATTERN] [varchar](120) NULL DEFAULT (NULL), [ISDELETED] [int] NOT NULL DEFAULT ('0'), [SUPERVISORID] [int] NOT NULL DEFAULT ('-1'), [RIGHTS] [int] NOT NULL DEFAULT ('0'), [SUPERVISORRIGHTS] [int] NOT NULL DEFAULT ('0'), [LOGGEDSERVER] [int] NOT NULL DEFAULT ('-1'), [DefaultSkill] [int] NOT NULL DEFAULT ((5)), [Details] [varchar](250) NULL DEFAULT (''), [SIP_Realm] [varchar](50) NULL DEFAULT (NULL), [SIP_HA1] [varchar](32) NULL DEFAULT (NULL), [SIP_Auth] [int] NULL DEFAULT ((0)), [PBX_Extension] [varchar](50) NULL DEFAULT (NULL))The link between this tables are:tblCRMA.clientid=tblCRMA_History.clientidtblCRMA_History.updatedbyuserid=agents.agentidI need to select all the fileds from tblCRMA where the column "esito" is not blank or null and to add to this result "agentname" column from the agents table and the "dateupdated"from the tblCRMA_History table.My big problem is that in the tblCRMA_History are more rows for a tblCRMA.clientid.so select * from tblCRMA where clientid= 1returns one rowbutselect * from tblCRMA_History where clientid=1 returns more rows,one for every field modified in tblCRMAI don't know how to add on my first select only the info I need.If you guys need more informations I'm ready to write it!Thanks!! |
|