Click here to Skip to main content
15,881,248 members
Home / Discussions / Database
   

Database

 
AnswerRe: selecting data from two tables Pin
Jörgen Andersson2-Apr-14 3:25
professionalJörgen Andersson2-Apr-14 3:25 
AnswerRe: selecting data from two tables Pin
Bernhard Hiller2-Apr-14 21:48
Bernhard Hiller2-Apr-14 21:48 
GeneralRe: selecting data from two tables Pin
Member 102635192-Apr-14 22:41
Member 102635192-Apr-14 22:41 
GeneralRe: selecting data from two tables Pin
Bernhard Hiller3-Apr-14 20:44
Bernhard Hiller3-Apr-14 20:44 
AnswerRe: selecting data from two tables Pin
BobWayne078-Apr-14 9:08
BobWayne078-Apr-14 9:08 
QuestionOracle Database Pin
Zeyad Jalil1-Apr-14 0:19
professionalZeyad Jalil1-Apr-14 0:19 
AnswerRe: Oracle Database Pin
thatraja3-Apr-14 1:02
professionalthatraja3-Apr-14 1:02 
QuestionSQL - Write Query with field names and table name stored in a table? Pin
Megan Jean27-Mar-14 11:11
Megan Jean27-Mar-14 11:11 
I work for an Insurance Company and creating a custom application. When we apply a coverage to a policy it is stored in a table with a Limit, Deductible, and Premium field. However, there are many coverages that do not follow the norm. They use different fields for Limit, Deductible, and Premium and are even stored in different tables. (Don’t ask why and don’t even try to understand the fact that they are STILL doing this so I need to leave logic to allow for additional coverages like this.) There is also no rhyme or reason to what fields they choose so varies greatly.

So, we have decided to create “LookUp” tables that will store all the information we need for a coverage. This avoids numerous joins – we were having issues with speed and performance of the application.

I need to find a way to prepopulate all these fields into a table. I would like the best option performance-wise. This will end up being a Nightly job – so when we receive a new snapshot of data we will run this query and prepopulate/update the values of the table.

Here is an example of my table, it contains the Coverage name (Coverage), the table (File), and the fields for the Limit, Deductible, and Premium. The PolicyNum field is a concatenation of LOB + Policy + Module. I need all three of these fields to join to a policy. I wanted to use a table since they will be adding new coverages. Keep in mind, I created this tables so can add more fields to it.

Here is the table I am referring to:

SQL
USE [PolicySummary]
  GO
  SET ANSI_NULLS ON
  GO
  SET QUOTED_IDENTIFIER ON
  GO

  CREATE TABLE [dbo].[Coverage](
      [CoverageID] [int] IDENTITY(1,1) NOT NULL,
      [LOB] [nvarchar](255) NULL,
      [Coverage] [nvarchar](255) NULL,
      [Description] [nvarchar](255) NULL,
      [File] [nvarchar](255) NULL,
      [Limit] [nvarchar](255) NULL,
      [Deductible] [nvarchar](255) NULL,
      [Premium] [nvarchar](255) NULL,
      [IsMultLimit] [bit] NULL,
      [IsMultDeductible] [bit] NULL,
      [IsMultPremium] [bit] NULL,
      [InsuranceLine] [nvarchar](255) NULL,
      [PolicyNum] [nvarchar](255) NULL,
   CONSTRAINT [PK_Coverage] PRIMARY KEY CLUSTERED
  (
      [CoverageID] 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


So in a nutshell, a policy may have the coverage BP0713. I then to look at this table and see that I need to run the following query:
SELECT BYAGVA as limit, BYPPTX as Deductible, BYA3VA as Premium FROM ASBYCPP WHERE BYARTX+BYASTX+BYADNB = @PolNum

The table contains the table name, the 3 fields, and the concatenation for the Policy Number.

Currently, I am looping through each coverage in a policy and selecting the values one at a time in a WHLIE Loop. Works but it is slow and I am hitting the query numerous times just to open the app (numerous units per policy so will be ran for each unit).

SQL
SELECT @SQL = N'SELECT @Limit=' + ISNULL(Limit, '''''') + N',@Deductible=' + ISNULL(Deductible, '''''') + N',@Premium=' + ISNULL(Premium, '''''') + N' FROM PHI_PIJ.dbo.' + [File] + N' WHERE ' + PolicyNum + N' = ''' + @PolNum +'''' + N' AND ' + @CovField + N'='''+Coverage +''''
FROM PolicySummary.dbo.Coverage
WHERE Coverage = @Coverage
AND LOB = @LOB

EXEC sp_executesql @SQL, N'@Limit nVarChar(255) output,@Deductible nVarChar(255) output,@Premium nVarChar(255) output', @Limit output, @Deductible output, @Premium output

INSERT INTO #OptCov2 VALUES(@Coverage, @Description, @LOB, @Limit, @Deductible, @Premium)


Can I get help with finding a way to populate my “Lookup” table each night so all I would have to do is “SELECT Limit, Deductible, PREMIUM FROM CoverageLookUp WHERE PolicyNum = @PolicyNum”

Here’s what I’ve got so far. It takes nearly 4 minutes to run the top 1000 records and there are a total of 614,497 records to run.

SQL
SELECT @SQL = N'SELECT @Limit=' + ISNULL(Limit, '''''') + N',@Deductible=' +   ISNULL(Deductible, '''''') + N',@Premium=' + ISNULL(Premium, '''''') + N'     FROM PHI_PIJ.dbo.ASBYCPP' + N' WHERE ' + PolicyNum + N' = ''' + @PolicyKey +'''' + N' AND BYAOTX' + N'='''+Coverage +''''
FROM PolicySummary.dbo.Coverage
WHERE Coverage = @Coverage
AND LOB = 'BOP'

EXEC sp_executesql @SQL, N'@Limit nVarChar(255) output,@Deductible nVarChar(255) output,@Premium nVarChar(255) output', @Limit output, @Deductible output, @Premium output

UPDATE PolicySummary.dbo.CoverageLkup
SET Limit = @Limit, Deductible = @Deductible, Premium = @Premium
WHERE CovAbbrev = @Coverage
AND PolicyKey = @PolicyKey

GeneralRe: SQL - Write Query with field names and table name stored in a table? Pin
PIEBALDconsult27-Mar-14 11:52
mvePIEBALDconsult27-Mar-14 11:52 
GeneralRe: SQL - Write Query with field names and table name stored in a table? Pin
Megan Jean28-Mar-14 4:51
Megan Jean28-Mar-14 4:51 
GeneralRe: SQL - Write Query with field names and table name stored in a table? Pin
PIEBALDconsult28-Mar-14 6:50
mvePIEBALDconsult28-Mar-14 6:50 
GeneralRe: SQL - Write Query with field names and table name stored in a table? Pin
Megan Jean28-Mar-14 12:17
Megan Jean28-Mar-14 12:17 
GeneralRe: SQL - Write Query with field names and table name stored in a table? Pin
PIEBALDconsult28-Mar-14 13:07
mvePIEBALDconsult28-Mar-14 13:07 
GeneralRe: SQL - Write Query with field names and table name stored in a table? Pin
Member 1071490931-Mar-14 22:45
Member 1071490931-Mar-14 22:45 
GeneralRe: SQL - Write Query with field names and table name stored in a table? Pin
PIEBALDconsult1-Apr-14 3:21
mvePIEBALDconsult1-Apr-14 3:21 
AnswerRe: SQL - Write Query with field names and table name stored in a table? Pin
GuyThiebaut28-Mar-14 5:31
professionalGuyThiebaut28-Mar-14 5:31 
QuestionRemove duplicate rows in multiple join query Pin
Eng Hasan Abbas25-Mar-14 7:56
Eng Hasan Abbas25-Mar-14 7:56 
AnswerRe: Remove duplicate rows in multiple join query Pin
Mycroft Holmes25-Mar-14 12:50
professionalMycroft Holmes25-Mar-14 12:50 
AnswerRe: Remove duplicate rows in multiple join query Pin
Chris Quinn25-Mar-14 22:02
Chris Quinn25-Mar-14 22:02 
AnswerRe: Remove duplicate rows in multiple join query Pin
Member 1071490931-Mar-14 22:55
Member 1071490931-Mar-14 22:55 
QuestionOracle Error Pin
Member 867725124-Mar-14 19:49
Member 867725124-Mar-14 19:49 
AnswerRe: Oracle Error Pin
Kornfeld Eliyahu Peter24-Mar-14 20:13
professionalKornfeld Eliyahu Peter24-Mar-14 20:13 
GeneralRe: Oracle Error Pin
Member 867725124-Mar-14 20:38
Member 867725124-Mar-14 20:38 
GeneralRe: Oracle Error Pin
Jörgen Andersson24-Mar-14 21:34
professionalJörgen Andersson24-Mar-14 21:34 
AnswerRe: Oracle Error Pin
Member 1043154927-Mar-14 0:28
Member 1043154927-Mar-14 0:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.