Parse comma separated value and map with other table to get Name and change it back to comma separate.

Hi,
I have one existing view(with around 15 fields), in which I have to add few more fields from table called PI.
Now these fields have values like (55C4444F-D83B-4F96-A011-367A3755BA6C , F52388E2-485B-49DF-8534-FDF46D23F59E , 722432E1-F063-4CBD-B83D-1B97836E82953) 3 values comma separated.(Sometimes only one value and sometimes 4 or 5 or 7-8 depend on user has entered
on web page)
Also I have another table called PHA and this tables has 2 fields Values and Name so I have to map this two tables based on VALUES fields and get Name from this PHA table and show in view and that also Comma separated.
So basically I have to Parse the PI table's Values field 1st, map it with PHA table to get Name and then Make it comma separated in that existing view.
To make fields comma separate I used below query,
(SELECT DISTINCT SUBSTRING
            SELECT ','+ PI.[Name]  AS [text()]
            FROM [DB].[dbo].[Table] PHA1
Inner Join  [DB].[dbo].[Table] PI
ON PHA.[Value] = PI.[VALUE]
            WHERE PHA1.PId =PHA2.PId and PHA1.CId = PHA2.CId
            ORDER BY PHA1.PId
            For XML PATH ('')
        ), 2, 1000) 
FROM [DB].[dbo].[Table] PHA2
Inner Join [cSharpSite_profiles].[dbo].[PetAllergies] PA
Inner Join  [DB].[dbo].[Table] PI
ON PHA.[Value] = PI.[VALUE]
) [Name]
Vicky

Wait, this sounds wrong. You have a view where you group values into a comma-separated list. While that surely will make some purists cringe, I can see that it makes sense from a presentation perspective.
But if you want to use these concatenated values as atomic values again, you should go back to the base tables and them from there. Building views on views may sometimes be a good idea, but if you are too keen on reuse you can cause a performance disaster.
So do it right from the beginning.
Erland Sommarskog, SQL Server MVP, [email protected]

Similar Messages

  • Records getting multiplied  by a factor of 3 when joining with other table

    When i query a table association_1 records for a particular network element i get 7 records
    but join it with rtts_association table to get the rtts_no i m getting 21 records.....
    the problems is ... 7 records are getting multiplied by a factor of 3 resulting in 21 records ....
    how can i avoid these extra records that appear in the second query
    SQL> select raised,cleared from association_1 where ne ='30434000/1MU';
    RAISED               CLEARED
    03-FEB-2011 22:03:10 03-FEB-2011 22:06:15
    12-FEB-2011 06:27:18 12-FEB-2011 06:29:51
    21-FEB-2011 21:36:44 22-FEB-2011 10:23:06
    23-FEB-2011 01:08:44 23-FEB-2011 06:56:53
    23-FEB-2011 17:06:16 23-FEB-2011 19:55:19
    23-FEB-2011 20:37:22 23-FEB-2011 23:01:21
    24-FEB-2011 00:33:17 24-FEB-2011 02:03:26
    SQL> select a.raised,a.cleared,b.rtts from association_1 a, rtts_association b where a.ne=b.ne and a.ne='30434000/1MU';
    RAISED               CLEARED                    RTTS
    03-FEB-2011 22:03:10 03-FEB-2011 22:06:15    1490980
    03-FEB-2011 22:03:10 03-FEB-2011 22:06:15    1487697
    03-FEB-2011 22:03:10 03-FEB-2011 22:06:15    1487649
    12-FEB-2011 06:27:18 12-FEB-2011 06:29:51    1490980
    12-FEB-2011 06:27:18 12-FEB-2011 06:29:51    1487697
    12-FEB-2011 06:27:18 12-FEB-2011 06:29:51    1487649
    21-FEB-2011 21:36:44 22-FEB-2011 10:23:06    1490980
    21-FEB-2011 21:36:44 22-FEB-2011 10:23:06    1487697
    21-FEB-2011 21:36:44 22-FEB-2011 10:23:06    1487649
    23-FEB-2011 01:08:44 23-FEB-2011 06:56:53    1490980
    23-FEB-2011 01:08:44 23-FEB-2011 06:56:53    1487697
    RAISED               CLEARED                    RTTS
    23-FEB-2011 01:08:44 23-FEB-2011 06:56:53    1487649
    23-FEB-2011 17:06:16 23-FEB-2011 19:55:19    1490980
    23-FEB-2011 17:06:16 23-FEB-2011 19:55:19    1487697
    23-FEB-2011 17:06:16 23-FEB-2011 19:55:19    1487649
    23-FEB-2011 20:37:22 23-FEB-2011 23:01:21    1490980
    23-FEB-2011 20:37:22 23-FEB-2011 23:01:21    1487697
    23-FEB-2011 20:37:22 23-FEB-2011 23:01:21    1487649
    24-FEB-2011 00:33:17 24-FEB-2011 02:03:26    1490980
    24-FEB-2011 00:33:17 24-FEB-2011 02:03:26    1487697
    24-FEB-2011 00:33:17 24-FEB-2011 02:03:26    1487649
    21 rows selected.

    For every combination of raised & cleared columns in "association_1" table, there are 3 records in the "rtts_association" table with different values for "RTTS" as below:
    Association_1:
    RAISED               CLEARED
    03-FEB-2011 22:03:10 03-FEB-2011 22:06:15
    rtts_association
    03-FEB-2011 22:03:10 03-FEB-2011 22:06:15    1490980
    03-FEB-2011 22:03:10 03-FEB-2011 22:06:15    1487697
    03-FEB-2011 22:03:10 03-FEB-2011 22:06:15    1487649Hence, evidently you wil get 7 (association_1) * 3 (rtts_association) in your output. If you want only one record in the output, you may need to pick any one of the values of RTTS from the 3 different values based on a pre-defined condition (e.g. record corresponding to lowest or highest value of RTTS)
    Cheers --

  • Must a EntityBean map with data table?

    I know Not every data table will map with Entity bean
    but must a EntityBean map with a datatable?
    rgds

    Ofcourse Not, EntityBean Just A style of Bean,
    We declare something as EntityBean because it perform some action like a Entity
    For Example,A Man Contain some attribute, or A File with some attribute,
    usually we have store this in the database ,so EntityBean Usually map with data table.
    but you can also store the data in the file format as you like,you can control it in the BMP model
    in my opinion ,Entitybean is the object base on the attribute , the Sessionbean is the object base on the action with the user.So we can distinguish them��:-)

  • While syncing iPad with my computer, i get an error message: cannot back-up to this computer

    while syncing iPad with my computer, i get an error message: cannot back-up to this computer. I'd like to know why?  Is it safe to download IOS6 if the ipad is not backed up?

    This is the same computer that I originally synced with the iPad and the first backup worked. Is there any way too solve this problem so I can upgrade to iOS 6

  • When opening a new tab, it opens onto a search engine, which is not what i want it to do. How do i resolve this and change it back to just a black page?

    when opening a new tab, it opens onto a search engine, which is not what i want it to do. How do i resolve this and change it back to just a black page?

    A new tab opens by default as a blank tab (about:blank).
    If that isn't the case then an extension has changed that behavior.
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes
    Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > Appearance/Themes).
    *Don't make any changes on the Safe mode start window.
    *https://support.mozilla.org/kb/Safe+Mode

  • HT1918 How to remove a credit card off my account and change it back to none

    How can I take credit card off my account and change it back to none

    Do you not see the None Option? If not, there is a reason so check here:
    iTunes Store Support
    http://www.apple.com/emea/support/itunes/contact.html

  • HT4914 How do i replace and change my back up music in itunes match?

    How do i replace and change my back up music in itunes match?

    What mail program are you using?
    If it’s Apple mail then goto Mail preferences and click on the signature tab.

  • I am an absolute newcomer to Lightroom.  I have downloaded images from camera (OMD EM1) and divided them into folders.  Some folders work ok in Develop mode.  With other folders I get the words "This file could not be found".  What should I do

    As an absolute newcomer to Lightroom 5 I have downloaded images direct from camera (IOlympus EM-1) and divided them into folders. When I go into Develop mode, some folders can be developed ok , but with images from two other folders I get the message "This file could not be found".  What should I do?

    may i suggest opening the files in Olymous Viewer 3  and exporting them (you can do some editing there if you wish or not) asTIFF files. After that you can import the new files into LR. LR seems to like tiiff more than .orf files 
    The advantage to using OV3 is that it seems to do a much better job converting RAW EM1 files. Colors are more accurate ( my red flower pot turned orange when loaded directly into lightroom)
    . The tiff files just LOOK better in LR  after the conversion . there is a youtube on this subject and when i tried it myself i was impressed 

  • How do I get a field to automatically select a value and change color based on another automatic field?

    Here is the situation:
    I have a row on a form called Finding Risk Rating. In this row are four fields: Probability, Severity, Risk Rating, Color.
    Probability is a drop down menu with the following values: 1, 2, 3, 4, 5
    Severity is a drop down menu with the following values: A, B, C, D, E
    Risk Rating is a field that I have a custom calculation script:
    var riskRating = this.getField("Probability").value+this.getField("Severity").value;
    event.value = riskRating;
    So, when I pick Probability = 1 and Severity = D, Risk Rating will automatically change to 1D, etc. This works fine on the surface as far as I can tell.
    The part where I am stuck, is the fourth field Color.
    Ideally, I want Color to be automatically populated depending on the value of Risk Rating. For example, for 1E I would want it to say "YELLOW" and the field to change color to yellow. For 1A it would be "GREEN" with the color green, etc.
    I tried doing an if else for all cases, but it never refreshes to the correct value. I then checked using app.alert to see what fields riskRating and colorRank are (see code below), and I noticed that riskRating never changes, even though the value in Risk Rating changes. Is there a way to order script(s) so that if I execute one, the other will follow? I'm new to scripting for forms and haven't done any programming in 10+ years, so feel free to rip my code in favor or something more efficient, or direct me to a good resource I can learn from.
    Here's the basis of what I have for scripting on Color. It's brief because I wanted to test it out before writing every 'if else' statement.
    var colorRank;
    var riskRating = this.getField("Risk Rating").value;
    if (riskRating = "1E") colorRank = "YELLOW";
    else if (riskRating = "1A") colorRank = "GREEN";
    else if (riskRating = "5A") colorRank = "RED";
    event.value = colorRank;
    app.alert("colorRank = " + colorRank + ", riskRating = " + riskRating);
    Any help is appreciated. Thanks!

    One problem is if more than one combo box item has the same number associated with it, you cannot simply set the export value to the corresponding number since they need to be unique (or the user interface behaves weird). One thing you can do is set up an object to associate a list item with a value, and look up the value in code when a list item is selected.
    For more information, see: http://acrobatusers.com/tutorials/2007/js_list_combo_livecycle

  • Join EQUI table with other table so as get address detail.

    Hi All,
    Can any one help me in the following case :
    I have to pass Equipment No. EQUNR on the selection screen and get Address detail (city, region, state, country, zipcode )
    now I am getting all this address related field in KNA1 table. Also I am able to join this two table with
    KNA1-KUNNR join EQUI-KUNDE as common field.
    Turning point
    when I am passing test data of Equipment No. EQUNR 60099204 I am not getting the address detail,
    because after passing EQUNR I am not getting KUNNR.
    So can any one please help me in joining EQUI table to some other table with field name so that I can get the address detail.
    Thanks

    Hi,
    The join between the table EQUI-kunde  join  KNA1-kunnr is ok but it not working for every value.
    Example :-
    In EQUI table when we pass  Equnr - 60099204 we need to get some value in KUNDE field, then only it will join to KNA1 table. But this is not happening, I am not getting value for KUNDE, hence join is not performing.
    So I need some other solution so that when we pass EQunr we can get the address details
    one thing more equnr  60099204 is having address detail, if we'll check IE03 (transaction by clicking address envelop)
    Thx.

  • Using Pipeline Table functions with other tables

    I am on DB 11.2.0.2 and have sparingly used pipelined table functions but am considering it for a project that has some fairly big (lots of rows) sized tables. In my tests, selecting from just the pipelined table perform pretty well (whether it is directly from the pipleined table or the view I created on top of it). Where I start to see some degregation when I try to join the pipelined tabe view to other tables and add where conditions.
    ie:
    SELECT A.empno, A.empname, A.job, B.sal
    FROM EMP_VIEW A, EMP B
    WHERE A.empno = B.empno AND
          B.mgr = '7839'
    I have seen some articles and blogs that mention this as a cardinality issue, and offer some undocumented methods to try and combat.
    Can someone please give me some advice or tips on this. Thanks!
    I have created a simple example using the emp table below to help illustrate what I am doing.
    DROP TYPE EMP_TYPE;
    DROP TYPE EMP_SEQ;
    CREATE OR REPLACE TYPE EMP_SEQ AS OBJECT
           ( EMPNO                                         NUMBER(10),
             ENAME                                         VARCHAR2(100),
             JOB                                           VARCHAR2(100));
    CREATE OR REPLACE TYPE EMP_TYPE AS TABLE OF EMP_SEQ;
    CREATE OR REPLACE FUNCTION get_emp return EMP_TYPE PIPELINED AS
    BEGIN
      FOR cur IN (SELECT
                    empno,
                    ename,
                    job
                  FROM emp
             LOOP
               PIPE ROW(EMP_SEQ(cur.empno,
                                cur.ename,
                                cur.job));
             END LOOP;
             RETURN;
    END get_emp;
    create OR REPLACE view EMP_VIEW as select * from table(get_emp());
    SELECT A.empno, A.empname, A.job, B.sal
    FROM EMP_VIEW A, EMP B
    WHERE A.empno = B.empno AND
          B.mgr = '7839'

    I am on DB 11.2.0.2 and have sparingly used pipelined table functions but am considering it for a project that has some fairly big (lots of rows) sized tables
    Which begs the question: WHY? What PROBLEM are you trying to solve and what makes you think using pipelined table functions is the best way to solve that problem?
    The lack of information about cardinality is the likely root of the degradation you noticed as already mentioned.
    But that should be a red flag about pipelined functions in general. PIPELINED functions hide virtually ALL KNOWLEDGE about the result set that is produced; cardinality is just the tip of the iceberg. Those functions pretty much say 'here is a result set' without ANY information about the number of rows (cardinality), distinct values for any columns, nullability of any columns, constraints that might apply to any columns (foreign key, primary key) and so on.
    If you are going to hide all of that information from Oracle that would normally be used to help optimize queries and select the appropriate execution plan you need to have a VERY good reason.
    The use of PIPELINED functions should be reserved for those use cases where ordinary SQL and PL/SQL cannot get the job done. That is they are a 'special case' solution.
    The classic use case for those functions is for the transform stage of ETL where multiple pipelined functions are chained together: one function feeds its rows to the next function which feeds its rows to another and so on. Each of those 'chained' functions is roughly analogous to a full table scan of the data that often does not need to be joined to other data except perhaps low volumn lookup tables where the data may even be cached.
    I suggest that any exploratory or prototyping work you do use standard relational tables until such point as you run into a problem whose solution might require PIPELINED functions to solve.

  • Case statement resulting into Left outer join with other tables

    Hi All ,
    I am facing a stuation where a Case statement on one of the logical columns in Answers is resulting into a left outer join with a table in the query.
    If we remove the case stmt, the table is not being acessed.
    The case stmt is a simple one and no other logical column is being accessed in the case stmt.
    Please advice .
    Thanks.

    Hi Sai,
    No ..we dont have any left outer join ...its just that I am selecting measure from F1 which has a confimred dimension D1 with F2.Now when I dont have case stmt on measure from F1(Case stmt is something like : CASE WHEN "- P table"."P Column" = 'Y' THEN 'Right' ELSE 'Wrong' END), then it doesnt query F2.
    However as soon as I introduce the case stmt ,the query creates a left outer join with F2.
    Thanks.

  • PSE 7 with windows 7 cannot get edited pics just  not back in Org ?

    Since installinng windows 7 I have not been able to edit pictures and have them back in Organizer just have a blank icon this happend after
    installing windows photo gallery. went to default tried to put defalt as Adobe photoshop elements organizer but it will only show
    editor. if I go to windows gallery the pic can be opened but why can't we have it  stay in pse?

    Try making a direct shortcut to the Organizer.
    Right click on the desktop and select New >> Shortcut
    Browse to Computer OS C:
    And find the PSE Organizer application in Program Files or Program Files (x86) on Windows 7 - 64 bit.
    Inside the Adobe >> Photoshop Elements Organizer (yellow folder) you are looking for an application file “PhotoshopEementsOrganizer” with six small icons (e.g. representing thumbnails)
    Select it and click OK
    Click next
    Rename by taking out Photoshop Elements leaving just the word Organizer
    Then click finish
    You should now be able to launch directly form the desktop by double clicking on the icon.

  • When i click on the new tab I dont get the google page but some other search engine, how do I change it back to google?

    My home page is the default Google page but when i click on open new tab and it loads some other search engine's site instead. How do I change that back to Google? I've checked for any random add-ons but that doesnt seem to be the problem...

    Does that still happen is you disable the RadioBar Toolbar?
    [http://support.mozilla.com/en-US/kb/troubleshooting+extensions+and+themes]

  • URGENT:Problem in a mapping with 8 tables in JOIN and using the DEDUP op.

    I have an urgent problem with a mapping: I must load data from 8 source tables (joined togheter) in a target table.
    Some data from 1 of the 8 tables have to be deduplicated, so I created a sort of staging table where I inserted the "cleaned" data, I mean, the deduplicated ones.
    I made it to make all the process faster.
    Then, I joined the 8 tabled, writing the join conditions in the operator properties, and connected the outputs into the fields of the target table.
    But..it does not work because this kind of mapping create a cartesian product.
    Then, I tried again with another mapping builted up in this way: after the joiner operator, I used the Match-Merge Operator and I load all data into a staging table exactly alike the target one, except for the PK (because it is a sequence). Then, I load the data from this staging table into the target one, and, of course, I connect to the target table also the sequence (the primary key). The first loading works fine (and load all the data as I expected).
    For the next loadings,I scheduled a pre-mapping process that truncate the staging table and re-load the new data.
    But..it does not work. I mean, It doesn't update the data previously loaded (or inser the new ones), but only insert the data, not considering the PK.
    So, my questions are as follow:
    1) Why loading the data directly from the joiner operator into the fact table doesn't work? Why does it generate a cartesian product??
    2) The "escamotage" to use the Match-Merge operator is correct? I have to admit that I didn't understand very well the behaviour of this operator...
    3) And, most of all, HOW CAN I LOAD MY DATA? I cannot find a way out....

    First of all, thanks for the answer!
    Yes, I inserted the proper join condition and in fact I saw that when WB generates the script it considers my join but, instead of using the fields in a single select statement, it builts up many sub-selects. Furthermore, it seems as it doesn't evaluate properly the fields coming from the source tables where I inserted the deduplicated data...I mean, the problems seems not to be the join condition, but the data not correctly deduplicated..

Maybe you are looking for

  • Vista SP1 russian support on Satellite P200-11L

    Hello! Does anyone have information about the vista sp1 support? I 've got notebook Satellite P200D-11L Is it safe to use Vista SP1? I use search driver under SP1 [LINK to driver|http://ru.computers.toshiba-europe.com/cgi-bin/ToshibaCSG/vista_drivers

  • I want to be a N guy

    I have MBP 15" Intel Core Duo 2GHz. The airport card is : AirPort Extreme (0x168C, 0x86). I installed the N enabler but Network Utility still shows me I am in a/b/g and my connection to my Airport Extreme 802.11n is at 54M. His my hardware supposed t

  • When I try to export my digital certificate (make a backup copy), firefox says that backup PKCS # 12 could not be done due to unknown causes.

    I obtained new digital certificate, which is working without any problems. When I try to export backup copy of new or already existing certificate, I get response window that exportation failed due to unknown reason. I use Firefox 3.6.14

  • Safari and extensions

    I installed extensions on Safari and all worked well. Some time later I noticed that when performing a Google search the 'traffic light' system did not work. I then realised that the other extensions were not behaving as they should. They appear in t

  • Proteger aplicacion

    buenas tardes estamos creando una aplicacion para escanear codigos de barra, la aplicacion ya la tenemos pero queremos proteger la aplicacion, es decir que la aplicacion solo corra en una pc, tener algun archivo tipo licencia. es esto posible?? hay c