Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
scottd
Starting Member
11 Posts |
Posted - 2007-01-03 : 11:33:08
|
| Hi All !Below is a snippet of MS SQL inside ASP 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 back green, red, blue, and yellow which is correct. On another similar search 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. I hope this makes sense. 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 = SQLSQL = 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 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-01-03 : 11:51:47
|
| Have you tried DISTINCT?Peter LarssonHelsingborg, Sweden |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2007-01-03 : 12:29:50
|
| Do all of your testing and troubleshooting using query analzyer, writing the sql directly. Do not try to debug and write SQL using ASP and concatenating together huge SQL Strings! you are making your life much harder than it needs to be.Once you have the T-SQL worked out, create a simple stored procedure and then call that from your ASP code. Again, the idea is to isolate one part of your app from the others and to work and debug and test one thing at a time. As it is, it could be the string manipulation in ASP causing problems, or how you are outputting the results onto your page, or something else causing the issue. Focus on the T-SQL alone using Query Analyzer first.- Jeff |
 |
|
|
|
|
|
|
|