USE [CMSQL]
GO
/****** Object:  Table [dbo].[icd10]    Script Date: 08/17/2015 15:49:48 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[icd10](
	[icd10code] [nvarchar](20) NOT NULL,
	[description] [nvarchar](256) NULL,
 CONSTRAINT [PK_icd10] PRIMARY KEY CLUSTERED 
(
	[icd10code] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[icd9]    Script Date: 08/17/2015 15:49:48 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[icd9](
	[icd9code] [nvarchar](20) NOT NULL,
	[description] [nvarchar](256) NULL,
 CONSTRAINT [PK_icd9] PRIMARY KEY CLUSTERED 
(
	[icd9code] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[diagcross]    Script Date: 08/17/2015 15:49:48 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[diagcross](
	[diagcrosskey] [bigint] IDENTITY(1,1) NOT NULL,
	[icd9] [nvarchar](20) NULL,
	[icd10] [nvarchar](20) NULL,
	[icd9ovrdesc] [nvarchar](256) NULL,
	[icd10ovrdesc] [nvarchar](256) NULL,
	[comment1] [nvarchar](1000) NULL,
	[comment2] [nvarchar](1000) NULL,
	[comment3] [nvarchar](1000) NULL,
	[active] [char](1) NULL,
 CONSTRAINT [PK_diagcross] PRIMARY KEY CLUSTERED 
(
	[diagcrosskey] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  View [dbo].[icd9View]    Script Date: 08/17/2015 15:49:51 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create view [dbo].[icd9View]
as select * from icd9
GO
/****** Object:  View [dbo].[icd10View]    Script Date: 08/17/2015 15:49:51 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create view [dbo].[icd10View]
as select * from icd10
GO
/****** Object:  View [dbo].[diagCrossView]    Script Date: 08/17/2015 15:49:51 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create view [dbo].[diagCrossView] as 
select 
[diagcrosskey]
      ,[icd9]
      ,[icd10]
      ,[icd9ovrdesc]
      ,[icd10ovrdesc]
      ,[comment1]
      ,[comment2]
      ,[comment3]
      ,[active]
, case when d.icd9ovrdesc IS null  then icd9.icd9code else d.icd9ovrdesc end
AS icd9desc
, case when d.icd10ovrdesc IS null  then icd10.icd10code else d.icd10ovrdesc end
AS icd10desc

 from diagcross d
 left outer join icd9 on d.icd9 = icd9.icd9code
 left outer join icd10 on d.icd10 = icd10.icd10code
GO
