Denormalizing With A Special Need

Sep 2, 2007

I have the following:

Demograph Table (PK MemberID)
-MemberID
-FirstName
-LastName

InsuranceSegments Table (PK = all columns combined)
-MemberID
-ProgramCode
-StatusCode
-BeginDate
-EndDate


I need to get the data into this table (i'll call the table MyTest)
-MemberID
-FirstName
-LastName
-BeginDate
-EndDate
-ProgramCode
-StatusCode

The catch:
For each record in the demograph table I need only one segment and that segment is to be based on the greatest EndDate.

What I need:
Give me the last segment for each demograph record and put each into it table MyTest

In my pseodo thinking
INSERT INTO MyTest (MemberID, FirstName, LastName, BeginDate, EndDate, ProgramCode, StatusCode)
SELECT
Demograph.MemberID, Demograph.FirstName, Demograph.LastName,
InsuranceSegments.BeginDate, InsuranceSegments.EndDate, InsuranceSegments.ProgramCode, InsuranceSegments.StatusCode
FROM
Demograph
INNER JOIN
InsuranceSegments
ON
Demograph.MemberID = InsuranceSegments.MemberID
WHERE { Need help :-) }
Need help with the where clause to get the segment with the 'highest/latest' EndDate


Sorry for the wall of text. I hope this is enough information to receive help and would like to thank you in advance for your time :-)

J

View 7 Replies


ADVERTISEMENT

Need Help With Denormalizing Query

Jul 10, 2006

Hello,I am currently working with a data mart. The business wants a view ofthe data that shows columns from the main table along with up to 6codes from a related table (not related by the full PK of the maintable though). They don't care about the order of the codes or how theyare assigned to their columns. Here is an example, which will hopefullymake this clearer:CREATE TABLE dbo.Main_Table (my_id INT NOT NULL,line_number SMALLINT NOT NULL,some_other_columns VARCHAR(20) NULL )GOALTER TABLE dbo.Main_TableADD CONSTRAINT PK_Main_Table PRIMARY KEY CLUSTERED (my_id, line_number)GOCREATE TABLE dbo.Related_Table (my_id INT NOT NULL,my_code CHAR(6) NOT NULL )GOALTER TABLE dbo.Related_TableADD CONSTRAINT PK_Related_Table PRIMARY KEY CLUSTERED (my_id, my_code)GO-- The two tables above are related by my_idINSERT INTO dbo.Main_Table (my_id, line_number) VALUES (1, 1)INSERT INTO dbo.Main_Table (my_id, line_number) VALUES (1, 2)INSERT INTO dbo.Main_Table (my_id, line_number) VALUES (1, 3)INSERT INTO dbo.Main_Table (my_id, line_number) VALUES (2, 1)INSERT INTO dbo.Main_Table (my_id, line_number) VALUES (2, 2)INSERT INTO dbo.Related_Table (my_id, my_code) VALUES (1, '22.63')INSERT INTO dbo.Related_Table (my_id, my_code) VALUES (1, '73.09')INSERT INTO dbo.Related_Table (my_id, my_code) VALUES (1, '51.23')INSERT INTO dbo.Related_Table (my_id, my_code) VALUES (2, '26.42')GOThe results that they would want to see are:my_id line_number my_code_1 my_code_2 my_code_3 my_code_41 1 22.63 73.09 51.23 NULL1 2 22.63 73.09 51.23 NULL1 3 22.63 73.09 51.23 NULL2 1 26.42 NULL NULL NULL2 2 26.42 NULL NULL NULLI'm pretty sure that I will need to load a table with the data in thisformat (or something similar) since generating this output on the flyfor the users will not work performance-wise (the main table is apartitioned table with 6 partitions, each containting 35M+ rows, whilethe related table is a single table that contains about 2M rows. Thereis additional logic that has to be done with a similar table of 90Mrows. So, I will try to load a table with this denormalized view of theworld. I could probably add some sort of sequence number toRelated_Table if you think that might help (then it just becomes asimple series of left outer joins).Any thoughts?Thanks!-Tom.

View 8 Replies View Related

When Denormalizing Is Essential

Jul 20, 2005

I have a database with over 450 tables, that until a short while agohas been strictly 3NF. In cases where complicated permutations ofdata are required quickly for certain parts of the system, sometimesit is not possible to write a query fast enough, due to the complexityof deriving many nested levels of data.Therefore for the few instances where this has been needed, I havecreated carefully named summary tables, having one-to-onerelationships to real tables (same primary key), and containing onlythe values which must be computed.This works fine. The question now is when to compute them.Much as I strongly dislike triggers, I have created triggers for thetables in question, which themselves recalculate the summary values,and populate the summary tables.Good news, loading is much faster.Bad news, now that I'm taking the hit on the save, the saves are fartoo slow.The only way I can see that my saves could be sped up, is to perhapsspread the work a bit, such that maybe if I am adding fifty records toa table, that the trigger is somehow disabled before the rows areadded, and re-enabled afterwards, to calculate the lot as a set-basedoperation (rather than calling the trigger 50 times), but I don't seea way to do that.Any help of any nature on this matter would be greatly appreciatedCheersBrian McGee

View 10 Replies View Related

Denormalizing Via SELECT

Apr 19, 2007

I have two tables related many-to-many so there's an intersection table in the middle. The first table is dbo.Event. It has a list of gigs (events) my company has booked to provide services for. The second table is dbo.Employee which has a list of employees. The intersection table dbo.EventEmployee contains which employee(s) have been scheduled to work. The intersection table has some status information whether the employee asked to work, is scheduled to work, etc. The data type is TINYINT

Here's what I want to do. Create a SELECT statement that basically denormalizes these three tables so the recordset looks like this:



Event.Name, Event.StartDate, Event.Location, Ed, Mary, Tom, Steve, Sally



The idea is to get the list of employees to become columns in the result set. If an employee is scheduled for the event there is a non-null value (Status), if an employee isn't scheduled there is a NULL in their column. For example:



CDC, 2/12/07, Chicago, NULL, 0, 0, NULL, NULL

NYC, 11/04/07, New York, 0, 0, 0, 0, NULL



The first record Mary & Tom are scheduled to work the CDC. The second row everyone except Sally is scheduled to work.



I've thought of cursor based solutions but performance will be rather poor. There are multiple places I want to use this type of solution so I'm hoping there's a more elegant way to accomplish this. SQL 2000 with latest SP. Help. This is beyond my SQL abilities.



harrier

View 9 Replies View Related

Denormalizing Data Query

Jan 24, 2008

Please help, I've used all of my capacities...



I need to denormalize some data...
I'll give an example.



Source table: (bold €“ PK)

ID_Company Data (yyyy-mm-dd) Type Quantity

FORD 2000-01-01 A 100

FORD 2000-06-01 A 200

FORD 2000-07-01 B 150

FORD 2002-01-01 A 400

FIAT 1999-01-01 A 300

FIAT 2000-06-01 B 700

FIAT 2001-07-01 B 750

FIAT 2002-01-01 C 250





Needed result set:

ID_Company Year A B C

FORD 2000 200 150 0

FORD 2002 400 150 0

FIAT 1999 300 0 0

FIAT 2000 300 700 0

FIAT 2001 300 750 0

FIAT 2002 300 750 250



A business rules:
· if there are more records for the same year and the same type, I extract the later date.



If more explanations are needed, please ask€¦I appreciate every help I can get with this query.

View 9 Replies View Related

A Special Thank You

Nov 17, 2004

I want to thank Brett Kaiser and Pat Phelan for advising me to get the "The Guru's Guide to Transcact-SQL" HOLY MOLY what an awesome book and the software that comes with it is so awesome "Sequin". This book is better then any of the Microsoft books, it breaks it all down for you and doesnt make it too difficult to understand I stayed up late last night reading this book. (which is why I'm exhausted today). This is by far the best Transact-SQL book I have ever come across.

THANKS GUYS :):):)

View 8 Replies View Related

Special Character

Dec 8, 2005

Hi,

i have the following problem:

I like to extract all special characters in one table with many fields.
How can I handle this without using 'replace' for each field and many characters ?

Thx. for ur suggestions.

dajm

View 2 Replies View Related

Special Characters

Jan 16, 2006

Hi All

I have a database I want to check whether any special characters are entered or not

E.g.

Post
-------

Director
Asst*Director
Ma^nager

I want to see all the entires where special characters like !@#$%^&*()_+ are entered

Plz help

Thanks

View 8 Replies View Related

Special Characters

Mar 10, 2008

Hi,

I an concatenating a string using char(187) as the separator. When I run the command "select char(187)" I get the symbol >>

However, when it writes to a csv file it is showing as an overscore instead.

Is there a known problem with special characters when writing to files?

View 2 Replies View Related

Special Character

Jul 20, 2005

How can I insert by asp a string containing 'That's the stringAsp code:SQL = "insert into tablename (columnA) values ('" & variable & "')"The problem is when variable contains a ' (single quote), it stops thestring definition and get an error.Can I do something?Thanks--Posted via Mailgate.ORG Server - http://www.Mailgate.ORG

View 2 Replies View Related

Special Characters

Apr 2, 2008

Our SQL 2005 databases have "SQL_Latin1_General_CP1_CI_AS"
collation settings on the server. One of tables has one column declared as "ntext".
When we try to insert "‚¬" character directly trough insert statement and retrieve it, we're getting right results. When we use web-services to insert data with this character (euro), and retrieving the data back, we're not getting this sign back. We are getting some characters like little squares. If I try to copy and paste them into notepad, I am getting ???
However, when I tried to place them here, I got them right:

‚¬ Å Å¡ Ž ž Å’ Å“ Ÿ

How can we assure visually they are inserted properly?

View 1 Replies View Related

Special Count

Feb 7, 2008

Hi everybody,

I need to write a special count on my table and I don't have idea how to do it.

I have an Audit table like that:

EventTime (DateTimeColumn) - Description (varchar) - UserID
----------------------------------------------------------------

2008-01-28 08:47:19 blabla User 12008-01-28 08:49:04 blabla User 1
2008-01-28 08:51:52 blabla User 2
2008-01-28 08:56:38 blabla User 3
2008-01-28 11:20:03 blabla User 2
2008-01-28 11:59:57 blabla User 32008-01-28 12:00:07 blabla User 32008-01-28 12:00:16 blabla User 32008-01-28 14:52:31 blabla User 32008-01-28 14:52:34 blabla User 4
2008-01-28 15:15:43 blabla User 4

I need to count the number of record for each user (on the datetime) BUT if there are x records in the same minute, I want to count it only one time.

Exemple: the user 1 and the user 3

For the user 1, the result should be 1 because there are 2 records for him, but 2 in the same minute.
For the user 3, the result should be 3 because there are 4 records for him, but 3 in the same minute.

I have any idea about the way to do it.
Your council are welcom ;o)

Thanks in advance
Jerome

View 6 Replies View Related

Cannot Use The Special Principal 'sa'

Aug 29, 2006

Hello,

I am starting to use SQL Server 2005. I am having trouble connecting remotely. I tried to enable the 'sa' user and got this error:

Cannot use the special principal 'sa'

Is the 'sa' user no longer valid for remote connections?

Thank you





View 11 Replies View Related

Cannot Use The Special Principle 'sa'

Jan 9, 2008

Ok, here's my issue... SQL 2005.

I have about 12 different databases, which about 4 of them are have no user mapped to it. Under the SA login, databases are mapped to the "dbo". The 4 I am having issues with have no user mapped. They are blank.

Here is where I am at... Security>Logins>sa>Login Properties>User Mapping

The columns are "Map", "Database", "User", and "Default Schema"

Here is an example of the correct Selection
Map=checked, Database=eDistribution, User=dbo, Default Schema=dbo


Now here is an example of a problem database
Map=unchecked, Database=FORMS, User=blank, Default Schema=blank

Here is the error when trying to add the "dbo" as a user

Any ideas?

TITLE: Microsoft SQL Server Management Studio
------------------------------
Create failed for User 'sa'. (Microsoft.SqlServer.Smo)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=9.00.1399.00&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=Create+User&LinkId=20476
------------------------------
ADDITIONAL INFORMATION:
An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)
------------------------------
Cannot use the special principal 'sa'. (Microsoft SQL Server, Error: 15405)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=09.00.1406&EvtSrc=MSSQLServer&EvtID=15405&LinkId=20476
------------------------------
BUTTONS:
OK
------------------------------

TITLE: Microsoft SQL Server Management Studio
------------------------------
Create failed for User 'dbo'. (Microsoft.SqlServer.Smo)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=9.00.1399.00&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=Create+User&LinkId=20476
------------------------------
ADDITIONAL INFORMATION:
An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)
------------------------------
User, group, or role 'dbo' already exists in the current database. (Microsoft SQL Server, Error: 15023)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=09.00.1406&EvtSrc=MSSQLServer&EvtID=15023&LinkId=20476
------------------------------
BUTTONS:
OK
------------------------------

View 1 Replies View Related

Special SQL Select Statement

Mar 1, 2007

Im starting a project that will be used to reserve rooms in a building.  My problem right now is writing an sql statement that will return a dataset with the proper results.  I have three tables setup below.  I need a dataset that returns rooms that are closed on a certain date and a set that returns open rooms on a particular date.I cant seem to figure out that sql statement... Any suggestions will be greatly appreciated.  tblRooms   pkRoomID   fkReservationID  tblDates   pkDateID   fkReservationID  tblReservation    pkReservationID    fkRoomID    fkDateID  

View 3 Replies View Related

SQL Query For Special Characters

Apr 18, 2007

On the bills that our system generates there is a comments field that users fillout. We have occasional problems with special characters in the text messing up the validation code. Does anyone know of a query that can identify special characters in a text field? Like carriage returns, tabs, etc.?
 Thanks, Dave

View 1 Replies View Related

A Special Order By Clause?

Aug 29, 2007

The following SELECT query gives me a list of 50 plus countries. How do I order them by 'United States' First (happens to be ID 225) and then alphabetical?
 SELECT Country_ID, Country_Long FROM Countries WHERE isIndustrial = 1 ORDER BY Country_Long

View 6 Replies View Related

Remove Special Caracters

Feb 7, 2005

how do i remove
in all of my fields in the table ? using a TSQL command ?

"DesktopModules/Events/Events.ascx
"

thanx !!

View 1 Replies View Related

Special Caracter In Update

Dec 7, 2000

I made a stored proc for update fields in a table everything is correct but when my new field contains a special caracter like *,/,[, ' , and a space too i have an error. I wrote it and i don't understand why it doesn't work.

CREATE PROCEDURE [sp_modif](@ID varchar(100),
@Table varchar(100),
@NewId varchar(100),
@CUSTOMER varchar(100),
@NewCUSTOMER nvarchar(255))

DECLARE @Commandvarchar(8000)
SELECT @Command = "UPDATE "+@Table+" SET ["+@CUSTOMER+"] = '"+@NewCUSTOMER+"' where ID like "+@NewId
execute (@Command)

Thank you

View 1 Replies View Related

BCP Issue-Special Characters

Jul 6, 2000

Iam working on sql server 7.0.

I have to bring in data from a text file into the sql server database. I use the BCP utility in pulling the data.

The flat file data contains special characters like ®. This is the registered trade mark symbol. When I bcp the file using the character mode the special characters are automatically changed to «. So If I am going to pull a data like ACRYLON®, after the BCP I get it as ACRYLON«.

Inorder to replace all these I have written a program but since it has to scan every record the time taken is more. Will in be possible to accomodate iun the BCP to pull the data with special characters.

If you have an answer to this please reply soon.

Thanks,

-Rajesh

View 2 Replies View Related

Special Characters - Search In DB

Mar 6, 2001

Hi !

I have an DB in SQL Server 7, and in Portuguese we have special characters like "á","õ",etc. And I want to let the visitor to a site to do a search (written in ASP), and not to need to write the correct way (without the accents). But either he writes or not in the correct way, the results are the same, not necessarly in the same order. Is there a SQL Server mechanism that permits this functionality, without doing a very complicated SELECT (takes a lot of time) or replicating a field in the DB (takes a lot of extra space)...

Thanks !
Filipe Lopes, Lisbon, Portugal.

View 2 Replies View Related

German Special Characters

Apr 13, 2003

I have a problem inserting German special chracters into a MSSql table.

üöäÖ works fine, but ßÜÄ are reduced to "_". I'm using a html form and a php script to enter the data into the database. Any idea why this isn't working? Funny thing is, when I use a german version of the SQL Server it also works without a problem... but I need this to work on ANY mssql server. Any help would be very much appreciated.

Michael

View 6 Replies View Related

Special Character;strange

Oct 6, 2004

I had to update pricelist at local-db on the basis of prices in another SQL by matching the description. When i JOIN the tables, no record gets displayed, but the descrptions at both tables were exactly the same i believed. Took a lot of time in identifying the discrepancy; the data was like this:

CREATE TABLE #ABC (price money, DESCRIPTION VARCHAR(200))
GO
INSERT #ABC SELECT 19999,'SQL2000
'
GO
SELECT * FROM #ABC WHERE DESCRIPTION ='SQL2000'
--(0 row(s) affected)
SELECT * FROM #ABC WHERE LTRIM(RTRIM(DESCRIPTION))='SQL2000'
--(0 row(s) affected)
select * from #ABC WHERE REPLACE(DESCRIPTION,'
','')='SQL2000'
--(1 row(s) affected)
GO
DROP TABLE #ABC
:rolleyes: I believe, ENTER has some value within a field.

View 14 Replies View Related

Replace Special Character

Feb 3, 2006

I'm trying to remove the special character ÿ from a varchar

select replace(my_col,'ÿ',' ')

this works, but the problem is that it also seems to replace the 'normal' y

(Database is case sensitive)

Why is that?

View 3 Replies View Related

Special Character Replacement

Mar 3, 2006

shailendra writes "Hi,everbody
lets come to my problem.I have one variable of type "ntext" which contain character "". i want to remove it or replace it with a blank character.

very urgent.....
waiting for the reply
shail"

View 1 Replies View Related

Can't Insert Special Characters

Jan 2, 2007

Hi, I'm new here. Happy new year!

Simple question. I can not insert special characters such as ' " ( ) etc. What special escape I need to put in my sql statement?

View 2 Replies View Related

Special Characher Issue

Feb 5, 2008

Hi,

I have a problem doing a query in ASP. This is my query:

Dim vardate
vardate = "#" & latestdate & "#"

sSQL1 = "SELECT tbl_size.sizename, tbl_stylesize.sizeid, tbl_stylesize.rate, tbl_stylesize.changedate " & _
"FROM tbl_stylesize " & _
"INNER JOIN tbl_size " & _
"ON tbl_stylesize.sizeid = tbl_size.sizeid " & _
"WHERE tbl_stylesize.active = -1 " & _
" AND FORMAT (vardate, "mm/dd/yyyy" ) = tbl_stylesize.changedate " & _
" AND tbl_stylesize.styleid = " & arrItem & _
" ORDER BY tbl_size.sizeid"

The problem is the " (ando may be also /)in the FORMAT date. It reconize it like a end of statement. I tryed to write

"" & mm & "/" & dd & "/" & yyyy & """ or
Chr(34) & mm/dd/yyyy & Chr(34)

but anything is working.
Can you please help me?

Best Regards,
Tom

View 8 Replies View Related

Special Characters In MSSQL.

Mar 7, 2006

Hi,I have a MSSQL Server communicating with an Oracle database through aMSSQL linked server using a MS ODBC connection.If I query the Oracle database through the Oracle ODBC 32Bit Test, theresult is fine:select addrsurname from address where addrnr = 6666;HÅKANSSONIf I do the same query within the SQL Query Analyzer (using the linkedserver), I get:select * from openquery(TESTSW, 'select addrsurname from address whereaddrnr = 6666');H?KANSSONI have tried to both check and uncheck the Automatic ANSI to OEMconversion, but the result remains the same.Does anyone know what to do to make the result display the specialcharacters in SQL Query Analyzer?Thanks,Kenneth

View 4 Replies View Related

Treatment Of Special Characters

Jul 20, 2005

Hi,This is a generic question, but for arguement's sake, let's say, myenvironment is SQL Server 2000.It seems that setting quoted_identifier off is the best way toaccomodate all sort of data input/update especially for data set thatcontains special characters like single quote as in O'Brien, otherfunky stuff like %^$*@#(!).However, this option won't help with a situation like data value of5'9",and let's say, we really can't predicate if this type of value will beused for ColA or ColB or ColC ...Examplecreate table #tmp (col1 varchar(30));set quoted_identifier off;insert into #tmp values("O'Brien's barking dog'");-- successinsert into #tmp values("O'book has funky (%^$*7) stuff");-- successinsert into #tmp values("John said "funky is OK" in his speech");-- failedGlobaly search and replace the double quotes before insert/update isjust too "expensive", not a good option.Now, if we can set a custom quoted_identifier, we can solve the aboveproblem easily, for instance,if MS SQL Server permits/acceptsset quoted_identier = '//$$';theninsert into #tmp values(//$$John said "funky is OK" in hisspeech//$$);(or the like)would succeedAny other thoughts/ideas? Thanks.Quote "Never stop thinking even though at times it may produce waste,which we all do, btw :) "

View 4 Replies View Related

What So Special About PostgreSQL And Other RDBMS?

Jul 20, 2005

Beside its an opensource and supported by community, what's the fundamentaldifferences between PostgreSQL and those high-price commercial database (andsome are bloated such as Oracle) from software giant such as Microsoft SQLServer, Oracle, and Sybase?Is PostgreSQL reliable enough to be used for high-end commercialapplication? Thanks

View 49 Replies View Related

Special Characters In TextBox

Jun 14, 2007

Currently I have got a report where I want to insert special characters (like @, !, ?) at the end of a String which will be displayed in a textbox of the report. Wenn I insert the String value "test!?" the report will return this value "!?test".



Does somebody know what is going wrong?

View 1 Replies View Related

Spaces And Special Characters

Aug 31, 2007

Good day
I've looked for information about this but to no avail. Essentially why does Reporting Services not support spaces and special characters in a Field Name?
I know that SQL supports spaces utilizing [] brackets e.g. [Field Name With Spaces]. So how come RS doesn't?
Thanks

View 1 Replies View Related

Help With A Special Stored Procedure

Jan 14, 2007

Hi

I have a table there have a primary key, this value have i also in another
table as a forreignkey, so good so far.

Here it is
If the number in may primarykey in table 1 , dosn't exits in table 2 then
delete records in table 1

I have made this in a ASP page with a view there list all records where the forreignkey in table 2 are NULL and then delte all records in table one

Can i made this as a stored procedure ?



regards



alvin

View 7 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved