Split the result of one column to multiple columns

Hi Experts,
Could you please help me to split the result of below query into multiple columns:
EXEC master..xp_cmdshell 'wmic service where "Caption Like ''%sql%''" get Caption , StartName, state'
I needs result of this query something like below but in tabular format:
Caption
StartName
State
SQL Server Integration Services 11.0
NT Service\MsDtsServer110
Running
SQL Full-text Filter Daemon Launcher (MSSQLSERVER)
NT Service\MSSQLFDLauncher
Running
SQL Server (MSSQLSERVER)
NT Service\MSSQLSERVER
Running
SQL Server Analysis Services (MSSQLSERVER)
NT Service\MSSQLServerOLAPService
Running
--------------------------------- Devender Bijania

Refer below query,
DROP TABLE #TEMP
CREATE TABLE #TEMP(COLS NVARCHAR(300))
INSERT INTO #TEMP
EXEC master..xp_cmdshell 'wmic service where "Caption Like ''%sql%''" get Caption , StartName, state'
SELECT *,
PATINDEX('% %',COLS) C1,
LEFT(COLS, PATINDEX('% %',COLS)) Caption,
LTRIM(RIGHT(COLS,LEN(COLS)-PATINDEX('% %',COLS))) ServiceName,
PATINDEX('% %',LTRIM(RIGHT(COLS,LEN(COLS)-PATINDEX('% %',COLS)))) C2,
LTRIM(RIGHT(LTRIM(RIGHT(COLS,LEN(COLS)-PATINDEX('% %',COLS))), LEN(LTRIM(RIGHT(COLS,LEN(COLS)-PATINDEX('% %',COLS)))) - PATINDEX('% %',LTRIM(RIGHT(COLS,LEN(COLS)-PATINDEX('% %',COLS)))))) State
FROM #TEMP
WHERE COLS IS NOT NULL AND RTRIM(LEFT(COLS, PATINDEX('% %',COLS))) <> 'Caption'
Regards, RSingh

Similar Messages

  • Copy the inspection  result  from one lot to multiples lots!!

    Hi SAP expert,
    I want to copy the inspection  result  from one lot to multiples lots, currently i know how to setup  the copy to another lot(SAML Response from SAP ID Service ) , but  i dont know to do to multiples lot.
    ¿Someone can help me?
    Thank you

    First you have to customizing the functionality of Copy of Inspection Results using the following path, where you have to entry the inspection types, plant .etc., where you want to have the functionality.
    SPRO -> Quality Management -> Quality Inspection -> Make Settings for Copy of Inspection Results
    Then when you are in Record Result screen you select Menu -> Edit -> Copy Inspection Results ,
    then a pop-up window is displayed and you filled in with the inspection lot which has the results and then another pop-up window is displayed to select the characteristics that you want to copy.
    A.P.

  • How can I separate one column into multiple column?

    How can I separate one column into multiple column?
    This is what I have:
    BUYER_ID ATTRIBUTE_NAME ATTRIBUTE_VALUE
    0001 PHONE_NUMBER 555-555-0001
    0001 EMAIL [email protected]
    0001 CURRENCY USD
    0002 PHONE_NUMBER 555-555-0002
    0002 EMAIL [email protected]
    0002 CURRENCY USD
    0003 PHONE_NUMBER 555-555-0003
    0003 EMAIL [email protected]
    0003 CURRENCY CAD
    This is what I would like to have:
    BUYER_ID PHONE_NUMBER EMAIL CURRENCY
    0001 555-555-0001 [email protected] USD
    0002 555-555-0002 [email protected] USD
    0003 555-555-0003 [email protected] CAD
    Any help would be greatly appreciated.

    This is another solution. Suppose your actual table's name is test(which has the redundant data). create a table like this:
    CREATE TABLE test2 (BUYER_ID number(10),PHONE_NUMBER varchar2(50),EMAIL varchar2(50),CURRENCY varchar2(50));
    then you will type this procedure:
    declare
    phone_number_v varchar2(50);
    EMAIL_v varchar2(50);
    CURRENCY_v varchar2(50);
    cursor my_test is select * from test;
    begin
    for my_test_curs in my_test loop
    select ATTRIBUTE_VALUE INTO phone_number_v from test
    where person_id=my_test_curs.person_id
    and attribute_name ='PHONE_NUMBER';
    select ATTRIBUTE_VALUE INTO EMAIL_v from test
    where person_id=my_test_curs.person_id
    and attribute_name ='EMAIL';
    select ATTRIBUTE_VALUE INTO CURRENCY_v from test
    where person_id=my_test_curs.person_id
    and attribute_name ='CURRENCY';
    INSERT INTO test2
    VALUES (my_test_curs.person_id,phone_number_v,EMAIL_v,CURRENCY_v);
    END LOOP;
    END;
    Then you will create your final table like this:
    create table final_table as select * from test2 where 1=2;
    After that write this code:
    INSERT ALL
    into final_table
    SELECT DISTINCT(BUYER_ID),PHONE_NUMBER,EMAIL,CURRENCY
    FROM TEST2;
    If you have a huge amount of data in your original table this solution may take a long time to do what you need.

  • How do I stop iTunes from breaking out all the songs in one album into multiple albums?

    How do I stop iTunes from breaking out all the songs in one album into multiple albums when the artist has many collaborators on the different songs, for example Timbaland?  I want to just listen to the full album with all the songs, instead of having to play every song separately.

    For your solution, see Steve MacGuire's helpful article:  http://samsoft.org.uk/iTunes/grouping.asp

  • Using the results of one Query in a workbook as a filter in another query

    Hello!
    I'd like to have one workbook which my users can execute and the result from one Query (e,g, Customer Account Number) will then be used as a filter in a second query (which would be from a different cube).
    Can this be done?
    Cheers.

    Hi,
    As far as I understand your requirement, you want to pass the result of one query to another query as a filter.
    Well you can do this, by Using Replacement Path Variable.
    For e.g. you want to pass Values of Custmomer Account Number to another query. In the second query, create one variable on Customer Account Number with type Replacment Path. Here it will ask you to enter the name of the query from which you would like to take the values of Customer Account Number.
    When you will run the second query , it will execute the first query from which you want to read the customer accoutn number in the back-end. And it willl display the output the second query as per the valeus of customer account number.
    This will help.
    - Jaimin

  • Performance of update query for single column vs multiple column

    Hi All,
    I could not find any answer for this, does it ever matter in terms of performance updating single column versus multiple column in a single update query.
    For eg. table consisting of 15 columns, what would be the difference in performance when one column is update in the single query against another update query where 15 columns are updated.
    Please do keep in mind my table columns in actually could be around 150+.
    Thanks for any information provided.

    If updated columns aren´t on where clause , then the only impact of 15 columns will be a increase on redo generation, and a possible chainning row.
    So since the redo is one of the things that have a large impact, the answer is yes.
    The performance will be slower.
    Regards
    Helio Dias.
    http://heliodias.com
    OCE SQL, OCP 9i

  • Split one row into multiple columns

    Hi,
    Data in one CLOB column in a table storing with delimiter, ##~~##. Ex. ##~~##abc##~~##defgh##~~##ijklm##~~##nopqr (data starts with delimiter). Please help me to split the data into multiple rows like below and it should be in the same order.
    abc
    defgh
    ijklm
    nopqr
    I am using Oracle 11g.
    Thanks.

    Thanks Hoek for your response. Before posting my question in the forum, I tried similar query. It is working with one character as delimiter.
    with test as (select 'ABC,DEF,GHI,JKL,MNO' str from dual )
    select regexp_substr (str, '[^,]+', 1, rownum) split
    from test
    connect by level <= length (regexp_replace (str, '[^,]+')) + 1;
    Above query is giving correct result by fetching 5 rows. I have modified the query like below...
    with test as (select 'ABC,,,DEF,,,GHI,,,JKL,,,MNO' str from dual )
    select regexp_substr (str, '[^,,,]+', 1, rownum) split
    from test
    connect by level <= length (regexp_replace (str, '[^,,,]+')) + 1;
    Above query resulting 13 rows and last 8 rows are nulls. Number of null rows are increasing, if I increase number of characters in delimiter. Could you please tell me how to avoid those null rows.
    Thanks.

  • Spliting the column Into multiple column diff secenario?

    I have one table say tab_det having two columns
    Tab_det
    Tab_tablename varchar2(50),
    Tab_tablename varchar2(50)
    Select * from tab_det;
    Tab_tablename     ---->          Tab_tablename
    ------------------ ------> ---------------------
    Emp          ------->          empno,empname,dept
    Emp_acct          ------>          empno,accno,accname,age
    I want to split the each column name from <Tab_tablename > because it contains all the
    Column name with comma separated and as a single value
    I want to split the column name for each < Tab_tablename> Corresponding to
    < Tab_tablename>
    And I want to pass the column names dynamically and the output need to be written into the File
    The Required Output In File
    Empno          empname          dept
    1          aaa               cs
    2          bbb               ec
    3          ccc               ec
    Empno          accno     accname     age
    1          12     aaa          34
    2          13 bbb          36
    3          14     ccc          38
    4          14     ddd          40

    Then do so.
    Use INSTR to identify the locations of the commas and SUBSTR to separate the pieces.
    We are not here to do your school work for you.

  • How to get the results in one line

    Hi
    if i use the script below i get the name of path and then : and in next line i get the results.is there a way to get the results from every path after the : and not in the next line?
    another question - is there a way that the script will not show the server name on every path?
    (Get-Counter -ListSet LogicalDisk).PathsWithInstances | Get-Counter
    THC

    If you take you script and pipe it to get member, it will give you a list of various script properties.
    (Get-Counter -ListSet LogicalDisk).PathsWithInstances | Get-Counter | get-member
    You will see that the object type returned by "Get-Counter" is Microsoft.PowerShell.Commands.GetCounter.PerformanceCounterSampleSet.
    TypeName:
    Microsoft.PowerShell.Commands.GetCounter.PerformanceCounterSampleSet
    Name MemberType Definition
    Equals Method bool Equals(System.Object obj)
    GetHashCode Method int GetHashCode()
    GetType Method type GetType()
    ToString Method string ToString()
    CounterSamples Property Microsoft.PowerShell.Commands.GetCounter.Perfo...
    Timestamp Property datetime Timestamp {get;set;}
    Readings ScriptProperty System.Object Readings {get=$strPaths = ""...
    You can try grabbing different properties, and they will print out differently, displaying the data on the same line in some cases. For example, pipe your output to a "foreach-object" block, and then for each object print out the CounterSamples property.
    (Get-Counter -ListSet LogicalDisk).PathsWithInstances | Get-Counter | foreach-object { ($_).CounterSamples }
    This should all print on one line now. However, you also asked if there was a way to not have the server print out on every line. The way to control the format of these outputs is to use the "format-table" cmdlet. So you would pipe your output to format-table
    and then give it various options. This is how you would pipe it (without any options).
    (Get-Counter -ListSet LogicalDisk).PathsWithInstances |
    Get-Counter | object { ($_).CounterSamples | format-table }#OR USE YOUR ORIGINAL CODE(Get-Counter -ListSet LogicalDisk).PathsWithInstances |
    Get-Counter | format-table }
    Now, it's up to you to give format-table the options you want. With no options, output will look unchanged. To see what options are available to you, use get-help.
    get-help format-table
    I hope this helps!
    Thank for all the info...

  • Using the results of one recordset to filter another.

    Hi
    I have a dynamically generated web page that uses a recordset to gather most of the relevant information that is needed on it. However, what i need to do is create a second record set on the same page and filter that second recordset using one of the results generated from the first recordset. The problem that i am having is that the first recordset displays its information as an echo <?php echo $row_Recordset1['move_type']; ?> but i obviously cannot use this echo code in the filter for the second recordset, the code obviously needs tweaking but i am not sure how.
    If it were as simple as copy and paste the query i would need for the recordset2 is as follows but i am unsure how to code the echo from the first recordset. I am well aware that the following code could never work but i hope it works as simplified example of my intention.
    SELECT ID, move_name, catagory_link_path, move_type, mem_on_off
    FROM moves
    WHERE move_type = <?php echo $row_Recordset1['move_type']; ?>
    ORDER BY move_name ASC
    Any help would be appreciated

    I can think of two ways this can be done. One way, (which may or may not be appropriate in your case) is to use an INNER JOIN. Here is an example:
    $presenterset1=mysql_query("SELECT * FROM presenters INNER JOIN presenters_course USING (presenter_id) WHERE course_id='$course_id' ORDER BY presenter_rank");
    Do a search for tutorials on INNER JOIN for information about how to use it.
    Another possible solution is to nest one SQL statement within the result of another: like this:
    $sql1=mysql_query("SELECT one, two, three from table1 WHERE one='$one'");
    while ($result1=mysql_fetch_assoc($sql1)){
    extract ($result1);
    $sql2=mysql_query("SELECT apple, orange, pear from table2 WHERE fruit='$three'");
    while ($result2=mysql_fetch_assoc($sql2)){
    extract ($result2);
    echo "$apple and $orange" and $pear<br/>";

  • Need to use the results of one query as an input to another query

    Hi, I have one sql query in my XML file, that returns more than one values for a column.
    and i want to use this output one by one as an input to the second query to retrive the data from the second query.
    Could please someone tell me if its possible in XML Publisher?
    If possible, please share the syntax to do the same
    For eg:
    Query 1:
    Select data1, data2 from query1 ; -- output data1 and data2
    want to use data1 and data2 one by one in the below query
    Query 2:
    select * from abc where name_id= data1/data2;
    Thanks and Regards
    Madhu

    Make sure your cursor declarations are in your declare section, not between the begin and end statements.

  • Convert one row to multiple column dynamic in smartform

    i want to convert on row to multiple column in smartform.As number of column is not per define..Please suggest the way out in smartform

    I saw a post and working perfect. The link is given below.
    http://scn.sap.com/community/abap/blog/2013/10/06/the-case-of-dynamic-columns-in-smartform
    Thanks to Eitan.

  • Split 1 column into multiple columns

    Hi
    How can we acheive this in Sql:
    Col 1
    abc def ghi jkl
    convert to:
    Col 1
    Col 2
    Col 3
    Col 4
    abc
    def
    ghi
    jkl
    Royal Thomas

    The best approach is to NOT split them out into individual columns... It violates the 1st normal form...
    Under first normal form, all occurrences of a record[sic] type must contain the same number of fields[sic].
    First normal form excludes variable repeating fields[sic] and groups.
    The better approach is to split them into rows, in their own table, with a foreign key reference back to the table you are pulling them away from.
    If you check my 1st post you'll see that I split the string with a function. That same a function can be used to populate the new table.
    Something along these lines...
    IF OBJECT_ID('tempdb..#BadOldDesign') IS NOT NULL
    DROP TABLE #BadOldDesign;
    CREATE TABLE #BadOldDesign (
    ID INT NOT NULL IDENTITY(1,1) PRIMARY KEY,
    ListOfCodes VARCHAR(100) NOT NULL
    INSERT #BadOldDesign (ListOfCodes) VALUES
    ('abc htr tbj yfd hjk mth'),
    ('bbb hyt tbj vyk hjk htd'),
    ('vvv nud'),
    ('yyy hyn tbj bdr '),
    ('htr htf tbj yfd hjk mko'),
    ('kio bhn tbj bjd hjk'),
    ('byd loj tbj yfd hjk cds');
    SELECT * FROM #BadOldDesign bod
    IF OBJECT_ID('tempdb..#ShinyNewTable') IS NOT NULL
    DROP TABLE #ShinyNewTable;
    SELECT
    bod.ID,
    sc8.ItemNumber,
    sc8.Item
    INTO #ShinyNewTable
    FROM
    #BadOldDesign bod
    CROSS APPLY dbo.SplitCSVToTable8K(bod.ListOfCodes, ' ') sc8;
    ALTER TABLE #ShinyNewTable ALTER COLUMN id INT NOT NULL;
    GO
    ALTER TABLE #ShinyNewTable ALTER COLUMN ItemNumber INT NOT NULL;
    GO
    ALTER TABLE #ShinyNewTable ADD CONSTRAINT pk_ShinyNewTable PRIMARY KEY CLUSTERED (ID, ItemNumber);
    SELECT * FROM #ShinyNewTable snt
    The dbo.SplitCSVToTable8K function that I'm using can be found here... http://www.sqlservercentral.com/articles/Tally+Table/72993/
    HTH,
    Jason
    Jason Long

  • BEX Formula  which gets the result of one keyfigure ..

    Hello all.
    I have two columns in my query. Lets say A and B. Column A is totaliza as an average and column B is totalize as a SUM.
    Now I want to have in another column C, for the item values the value of column A and for the Result value (total) te result of colum B.
    Example:
            A   B     C
            1   0,1   1
            2   0,3   2
            5   0,5   5
            2   0,5   2
    TOTAL   2   5     5 
    Is it possible?
    Thanks ..

    Could you please elaborate , the format changed here , I can not make out the columns.
    Thanks

  • How to pass the result of one script to another?

    Hi
    Is there any possibility to pass info from one script to another? I run some scripts at night and they have to use the results I get during the day...
    Thank you in advance for any help
    Vera

    There's a couple of ways of doing this.
    It sounds like the second script isn't being called directly from the first one, so you can't pass the data directly, so that leaves you with a couple of options.
    One is to have the first script write the data to a file, then have the second script read that file.
    The other would be to store the data as a property in the first script - properties are saved between executions - then have the second script read the first script's property when it starts up.
    For the first option, just have the script write the data to a file:
    set myData to "here's the data to save"
    set myFile to (open for access file (path to home folder as text & "data.file") with write permission
    write myData to myFile starting at 0
    close access myFile
    Now the second script can read the file:
    set otherScriptsData to read file (path to home folder as text & "data.file")
    For the second option, just store the data as a property:
    property myData:""
    set myData to "here's the data to save"
    Now loading the data in the second script goes like:
    set otherScript to load script file "path:to:other.scpt"
    set otherScriptsData to otherScript's myData
    Here you can see the second script loading the script then reading its myData property.

Maybe you are looking for