Showing posts with label entries. Show all posts
Showing posts with label entries. Show all posts

Saturday, February 25, 2012

removing duplicate entries in SQL Field

Hi All,

Below is a snippet of MS SQL inside some VB that retieves
Commodity info such as product names and related information and returns the results in an ASP Page. My problem is that with certain searches, elements returned in the synonym field repeat. For instance, on a correct search I get green, red, blue, and yellow which is correct. On another similar search with different commodity say for material, I get Plastic, Glass,Sand - Plastic, Glass,Sand - Plastic, Glass, Sand. I want to remove the repeating elements returned in this field. IOW, I just need one set of Plastic, Glass and Sand. I hope this makes sense.

Below is the SQL and the results from the returned page.


PS I tried to use distinct but with no luck I want just one of each in the example below.

Thanks in Advance!

Scott

==============================

SQL = ""
SQL = "SELECT B.CIMS_MSDS_NUM," & _
"A.COMMODITY_NUMBER, " & _
"B.CIMS_TRADE_NME," & _
"B.CIMS_MFR_NME," & _
"B.CIMS_MSDS_PREP_DTE," & _
"B.APVL_CDE," & _
"COALESCE(C.REGDMATLCD,'?') AS DOTREGD," & _
"COALESCE( D.CIMS_TRADE_SYNM,'NO SYNONYMS') AS SYNONYM, " & _
"A.MSDS_CMDTY_VERIF, " & _
"A.CATALOG_ID " & _
"FROM ( MATEQUIP.VMSDS_CMDTY A " & _
" RIGHT OUTER JOIN MATEQUIP.VCIMS_TRD_PROD_INF B " & _
" ON A.CIMS_MSDS_NUM = B.CIMS_MSDS_NUM " & _
" LEFT OUTER JOIN MATEQUIP.VDOT_TRADE_PROD C " & _
" ON A.CIMS_MSDS_NUM = C.MSDSNUM " & _
" LEFT OUTER JOIN MATEQUIP.VCIMS_TRD_PROD_SYN D " & _
" ON B.CIMS_MSDS_NUM = D.CIMS_MSDS_NUM) "

SQL1 = ""
SQL1 = SQL

SQL = SQL & "WHERE " & Where & " "
==================================

Here is a piece of the problem field, note repeating colors etc.

CCM-PAINTS & COATINGS (1/26/98)F65E36 ORANGE F65W1 GLOSS WHITEF65B50 WR. IRON FLAT BLACK F65R2 TARTAR RED DARKF65B4 SEMI-GLOSS BLACK F65R1 VERMILIONF65B1 GLOSS BLACK F65N11 RICH BROWNF65A49 ASA #49 GRAY F65M1 MAROONF65A4 MACHINE TOOL GRAY F65L10 BRIGHT BLUEF65A2 LIGHT GRAY F65L7 PALE BLUEF65A1 WARM GRAY F65L6 TURQUOISEF65L4 DARK BLUEF65L3 LIGHT BLUE V65V100 MIXING CLEARF65H1 IVORY F65Y48 LIGHT YELLOWF65G41 FOREST GREEN F65Y44 LEMON YELLOWF65G40 MEDIUM GREEN F65W100 MIXING WHITEF65G39 LIGHT GREEN F65W4 TINTING WHITEF65G16 SEMI-GLOSS MACHINERY GRE F65W3 CUSTOM WHITEF65E37 INTERNATIONAL ORANGE F65W2 SEMI-GLOSS WHITEF65B50 WR. IRON FLAT BLACK F65R2 TARTAR RED DARKF65B4 SEMI-GLOSS BLACK F65R1 VERMILIONF65B1 GLOSS BLACK F65N11 RICH BROWNF65A49 ASA #49 GRAY F65M1 MAROONF65A4 MACHINE TOOL GRAY F65L10 BRIGHT BLUEF65A2 LIGHT GRAY F65L7 PALE BLUEF65A1 WARM GRAY F65L6 TURQUOISEDISAPPROVED BY CCM-PAINTS & COATINGS (1/26/98)F65L4 DARK BLUEF65L3 LIGHT BLUE V65V100 MIXING CLEARF65H1 IVORY F65Y48 LIGHT YELLOWF65G41 FOREST GREEN F65Y44 LEMON YELLOWF65G40 MEDIUM GREEN F65W100 MIXING WHITEF65G39 LIGHT GREEN F65W4 TINTING WHITEF65G16 SEMI-GLOSS MACHINERY GRE F65W3 CUSTOM WHITEF65E37 INTERNATIONAL ORANGE F65W2 SEMI-GLOSS WHITEF65E36 ORANGE F65W1 GLOSS WHITEDISAPPROVED BY CCM-PAINTS & COATINGS (1/26/98)F65A2 LIGHT GRAY F65L7 PALE BLUEF65A1 WARM GRAY F65L6 TURQUOISEF65B4 SEMI-GLOSS BLACK F65R1 VERMILIONF65B1 GLOSS BLACK F65N11 RICH BROWNF65A49 ASA #49 GRAY F65M1 MAROONF65A4 MACHINE TOOL GRAY F65L10 BRIGHT BLUEF65L4 DARK BLUEF65L3 LIGHT BLUE V65V100 MIXING CLEARF65H1 IVORY F65Y48 LIGHT YELLOWF65G41 FOREST GREEN F65Y44 LEMON YELLOWF65G40 MEDIUM GREEN F65W100 MIXING WHITEF65G39 LIGHT GREEN F65W4 TINTING WHITEF65G16 SEMI-GLOSS MACHINERY GRE F65W3 CUSTOM WHITEF65E37 INTERNATIONAL ORANGE F65W2 SEMI-GLOSS WHITEF65E36 ORANGE F65W1 GLOSS WHITEF65B50 WR. IRON FLAT BLACK F65R2 TARTAR RED DARKF65A1 WARM GRAY F65L6 TURQUOISEDISAPPROVED BY CCM-PAINTS & COATINGS (1/26/98)F65B1 GLOSS BLACK F65N11

Hi,

if you are using denormalized stored values, you will first have denormalized them to use SQL Server functions for grouping / distinct them. You will have to separate the values first using a separator and using a function like this one here:

HTH, Jens K. Suessmeyer.

http://www.sqlserver2005.de

Removing Duplicate Entries from a Parent-Child Hierarchy

I have defined a Parent-Child hierarchy for one of my dimensions. (It is a flavour of organisation structure)

However, when I process it, each node repeats itself as one of its own children.

What is going on here and how can I fix this? Someone mentioned a property I can set, but nothing jumps out at me.

It's the datamember, no? If you drag and drop theses members for a MDX query it brings the .datamember in the end of the member? If so, just set to hidden the datamember.

The parent-child attribute has a property named "MemberWithData" set to "NonLeafDataHidden".

|||

Handerson is right.

You have the change the default property to get the desired effect.

The default scenario which AS2005 is where a sales mgr and his salesmen all sell products and you wnat to display revenue for them.

The alternative might be that only the salesmen sell and the manager does not have any sales, Then you ahve to reconfigure the property defined above.

|||

I don't understand what you guys are talking about... when I browse the hierarchy of my parent child relationship, for each parent node there is a child node with the same name and properties when the dimension is processed. This is before we even run any MDX...

|||

Let's look a sample, if you have the parent-child dimension entity like that:

America|||Thanks for the clarification ... much appreciated.

Removing duplicate entries

Hi,

I would lke to know what is the best way to remove duplicate entries from a GIANT table ?

I'm using this but I think that too slow..

IF EXISTS (SELECT * FROM DBO.SYSOBJECTS WHERE ID = OBJECT_ID(N'[DBO].[#PABX_TEMP]') AND OBJECTPROPERTY(ID, N'ISUSERTABLE') = 1)
DROP TABLE [DBO].[#PABX_TEMP]

CREATE TABLE [#PABX_TEMP] (
[CHAVE] [int],
[COD_CLIENTE] [varchar] (50) COLLATE Latin1_General_CI_AS NULL ,
[DATA_HORA] [datetime] NULL ,
[NRTELEFONE] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
[RAMAL] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
[WCOS] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
[TEMPO_SEGUNDOS] [real] NULL ,
[TIPO] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
[TIPO_ORIGINAL] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
[TRONCO] [varchar] (50) COLLATE Latin1_General_CI_AS NULL ,
[TEMPO_ATENDIMENTO] [real] NULL ,
[JAPROCESSADO] [int] NULL ,
[VALOR] [money] NULL ,
[VALOR_CONC] [money] NULL ,
[VALOR_TARIFA] [money] NULL ,
[VALOR_TARIFA_CONC] [money] NULL ,
[CLASSIFICA] [varchar] (50) COLLATE Latin1_General_CI_AS NULL ,
[LOCALIDADE] [varchar] (255) COLLATE Latin1_General_CI_AS NULL ,
[VALOR_TEMPO] [money] NULL ,
[NUMERO_E1] [varchar] (50) COLLATE Latin1_General_CI_AS NULL ,
[BLOQUEADO] [bit] NULL ,
[DATA_BLOQUEIO] [datetime] NULL ,
[TRANSFERIDO] [varchar] (255) COLLATE Latin1_General_CI_AS NULL
)

INSERT INTO #PABX_TEMP
SELECT MIN(CHAVE) as 'CHAVE', [COD_CLIENTE], [DATA_HORA], [NRTELEFONE],
[RAMAL], [WCOS], [TEMPO_SEGUNDOS], [TIPO], [TIPO_ORIGINAL],
[TRONCO], [TEMPO_ATENDIMENTO], [JAPROCESSADO], [VALOR], [VALOR_CONC],
[VALOR_TARIFA], [VALOR_TARIFA_CONC], [CLASSIFICA], [LOCALIDADE],
[VALOR_TEMPO], [NUMERO_E1], [BLOQUEADO], [DATA_BLOQUEIO], [TRANSFERIDO]
FROM PABX WHERE (BLOQUEADO = 0 OR BLOQUEADO IS NULL)
GROUP BY [COD_CLIENTE], [DATA_HORA], [NRTELEFONE],
[RAMAL], [WCOS], [TEMPO_SEGUNDOS], [TIPO], [TIPO_ORIGINAL],
[TRONCO], [TEMPO_ATENDIMENTO], [JAPROCESSADO], [VALOR], [VALOR_CONC],
[VALOR_TARIFA], [VALOR_TARIFA_CONC], [CLASSIFICA], [LOCALIDADE],
[VALOR_TEMPO], [NUMERO_E1], [BLOQUEADO], [DATA_BLOQUEIO], [TRANSFERIDO]

DELETE FROM PABX WHERE (BLOQUEADO = 0 OR BLOQUEADO IS NULL) AND CHAVE NOT IN (SELECT CHAVE FROM #PABX_TEMP)

DROP TABLE #PABX_TEMP

Thanks

Try replacing your NOT IN with NOT EXIST; NOT EXIST tends to be more efficient. Here are some posts to reference:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=299702&SiteID=1
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=532892&SiteID=1
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=607796&SiteID=1

|||

OK, I'm gonna test

Thanks

Removing Databases

Using SQL Server Management Studio, I see 4 entries, master, model, msdb and temdb, under Databases -> System Databases. Which of these can I safely remove, if any?

Thank you

Hi there,

I don't think you should remove any of them....Each of the system databases is there for a purpose and removing one or more will adversely affect your database server (possibly to the point of inoperability).

Below is a link to adescription of the purpose of each system database:
System Databases

Hope that helps a bit or sheds some light on the matter, but sorry if it doesn't
|||Why should one delete the system databases ?

HTH, Jens Suessmeyer.

http://www.sqlserver2005.de
|||

Nate,

Thank you for the reponse, it helped quite a bit. I am new to SQL Express and I wasn't sure what those Db's were for, so the link is very helpful.