Fetch only required fields from SQL Table

Hi,
We have a table like below which will get data thru a job.
And I'm writing a Job/SP which will fetch 4 fields from that table and send  them in a Email to Admins informing how many new employee are added newly.
How to loop thru these fields  and not only there might be a chance where we will have 100 records and I need to take only first 30 of them and send.
EmpId
Empname
Deptname
Designation
 Can any one has any solution on achieving this?
Thanks

Please refer the below link:
http://beyondrelational.com/modules/2/blogs/77/posts/11386/sql-server-t-sql-different-ways-to-generate-a-comma-separated-string-from-a-table.aspx
You need to use the Top30 query as your table in the script :
select top 30 EmpID,EmpName,DeptName,Designation
from tbl_name
order by EmpID
Eg: You may need to do for other columns:
--WARNING: THIS SCRIPT IS PROVIDED AS-IS AND WITHOUT
-- WARRANTY.
-- FOR DEMONSTRATION PURPOSES ONLY
--Step 01: Generate Temp table to store source data
DECLARE @NamesTable TABLE (Id INT,
Name NVARCHAR(50))
--Step 02: Generate test data
INSERT INTO @NamesTable VALUES (1,'A'),
(2,'D'),
(2,'C'),
(3,'E'),
(3,'H'),
(3,'G')
DECLARE @listIds VARCHAR(MAX) --DO NOT initialize this one!
SELECT @listIds = COALESCE(@listIds + ',' ,'') + Cast(nt.Id as varchar(10))
FROM @NamesTable nt Order by ID asc
DECLARE @listNames VARCHAR(MAX) --DO NOT initialize this one!
SELECT @listNames = COALESCE(@listNames + ',' ,'') + nt.Name
FROM @NamesTable nt Order by ID asc
SELECT 'EmpID: ' + @listIds+', EmpName: ' + @listNames

Similar Messages

  • Get the Last Value of Status Field from SQL TABLE using SQL 2008

    I have a table with Fields such as
    UploadstartTime, UploadEndtime, STATUS From TBLA.
    The STATUS Field, has values =7 and 11 are failed and 12 is SUCCESS. I cannot do a max, since it will always show 12, I need to get the MAX(UPLOADENDTIME, and get STATUS For that record. How can I do that using 1 SQL Query?
    My current code is: The issue is
    select
      TBLNAME
    MaxUploadstarttime
    =
    max(UploadStartTime),
    MaxUploadEndtime
    =
    max(UpLoadEndTime),
         Status=max(status)
    from  DB.DBO.LOGTABLE
    p1

    Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. You failed! Temporal
    data should use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect. 
    This is minimal polite behavior on SQL forums. 
    >> I have a table with Fields such as <<
    Fields are not columns! There is no generic status in RDBMS. Putting “tbl-” in a table name is called tibbling and we make fun of people who do it (Google Phil Factor's humor columns. If you were polite is this what you wanted to post? 
    CREATE TABLE Something_Uploads
    (upload_source_name CHAR(15) NOT NULL,
     upload_start_timestamp DATETIME2(0) NOT NULL,
     PRIMARY KEY (upload_source_name, upload_start_timestamp),
     upload_end_timestamp DATETIME2(0),
     CHECK(upload_start_timestamp < upload_end_timestamp),
     upload_status INTEGER NOT NULL 
       CHECK (upload_status IN (7,11,12, ..))
    >> I cannot do a max, since it will always show 12, I need to get the MAX(UPLOADENDTIME, and get upload_status For that record [sic]. How can I do that using 1 SQL Query?  <<
    Since you told us nothing and gave no sample data, want to correct this postign? 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • How i can get only required data from table by using CKM

    Hi...
    i have done one scenerio i.e get required data from one table into another table on basis of some condition by using CKM.
    Now i want same,but this time my target is file ,not RDBMS.
    so plz tell me procedure how i can get required data from source table into File on basis of some condition using CKM.
    thanks

    CKM checks for Constraints and Not Null condition. You can use IKM SQL to File and being that there is no option in IKM for CKM .
    The other method is you can declare those Not null and other condition as Filter in the Source Datastore, that should filter out records that you are not willing to move to files.

  • CRS Editor - Retrieving Timestamp database field from SQL 2005

    Hello -
    For the life of me, I cannot retrieve a database timestamp field from SQL 2005.
    I have successfully used 'cast(Date as char(30)) as DateStr' to convert to string but the DBRead statement displays the original object only as java.lang.Timestamp.  Any posts regarding this topic usually require Java skill sets above my level (creating new java class for import,...).
    There has to be an easy way to do this without being a Java programmer, yes?
    Any help here would greatly be appreciated!
    Thanks
    Andy Backus
    941.587.7199

    Andy,
    I'm guessing you know that this isn't really a date/time value in MS SQL.  According to Microsoft: 
    The Transact-SQL timestamp data type is not the same as the timestamp data type defined in the SQL-92 standard. The SQL-92 timestamp data type is equivalent to the Transact-SQL datetime data type.
    But to your question how to get the timestamp value out in a string...You'll want to use the convert function:
    select convert(varchar(10),myTimestampField) from myTable
    That will return the hex value in the column in a string format.  Also, when you retrieve the data, are you looking at the original table (which specifies the column is a timestamp), or did you create a dummy table with the columns named and formatted the way the data will be returned that UCCX can look at for the schema?  If it doesn't have the correct schema to look at, you'll have problems.
    Cliff
    please rate helpful posts

  • How to get Required field from R/3 to  load in Bw.

    To get a perticular value from R/3 to BW . in r/3 side I need to go to first table equi from there i pick equipmentno on the basis of this number i need to go to objnr from objnr i need to pick up objnr number and i have to see this number's value in table AUSP. like this same scenario i am facing in master as well as transaction tables , how i should fetch these values and load to BW .
    In standard datasources if i want to add the field value of which is derived by the value in two more tables then how do i Enhance the datasource.
    Can any one give clue to resolve It.

    Hi Srinivas,
       If you want to enhance any data source, by appending any field from any table.. basic rules are
    1. All the key fields in that perticular table should be available in your data source.
    2. Similar for more fields from different tables.
       Or if you want to extract more fields from different tables try to create a View on these table and go for generic extraction(create data source on this View). Choose which one if best option for your requirement.
    Hope it Helps
    Srini

  • How to print the data  if we take different fields from diffrent tables

    Hi ABAPers,
    I take diff fields from 3 tables. Those are
    these fields from EKBE
           EBELN
           EBELP
           BELNR
           BUZEI
           BWART
           BUDAT
           AREWR
           REEWR
           WERKS
           MWSKZ
    these fields from EKKO
           BUKRS
           BSART
           WAERS
    these field from EKPO
           TXZ01
           MATNR
           MTART
    I want to print the data all fields.What logic can i write?
    Please help me for this question and i am waiting for your response.
    Regards,
    Raja Sekhar.

    Hi,
    First you have to fetch data from all the three tables and then consolidate into final table.
    In Declaration:
    1.Declare Internal Table for EKKO holding:
    EBELN
    BUKRS
    BSART
    WAERS
    2.Declare Internal Table for EKPO holding:
    EBELN
    EBELP
    TXZ01
    MATNR
    MTART
    3.Declare Internal Table for EKBe holding:
    EBELN
    EBELP
    BELNR
    BUZEI
    BWART
    BUDAT
    AREWR
    REEWR
    WERKS
    MWSKZ
    *==> This table has
    MANDT
    EBELN
    EBELP
    ZEKKN
    VGABE
    GJAHR
    BELNR
    BUZEI
    as Primary keys field,you should have values for all the PK aotherwise you will get multiple entries*
    4.Declare a Final Internal Table i_final with all the fields you want
    EBELN
    EBELP
    BUKRS
    BSART
    WAERS
    TXZ01
    MATNR
    MTART
    BELNR
    BUZEI
    BWART
    BUDAT
    AREWR
    REEWR
    WERKS
    MWSKZ
    Data Fetching
    select EBELN
    BUKRS
    BSART
    WAERS
    from EKKO
    into table i_ekko
    where .........<selection criteria>.
    if not i_ekko is initial.
    select EBELN
    EBELP
    TXZ01
    MATNR
    MTART
    from EKPO
    into table i_ekpo
    for all entries in i_ekko
    where EBELN = I_EKKO-EBELN
    AND ......<If any other selection criteria>.
    if not i_ekpo is initial.
    select EBELN
    EBELP
    BELNR
    BUZEI
    BWART
    BUDAT
    AREWR
    REEWR
    WERKS
    MWSKZ
    from EKBE
    into table i_ekbe
    for all entries in i_ekpo
    where ebeln = i_ekpo-ebeln
    and ebelp = i_ekpo-ebelp
    and ..........<If any othet selection criteria>
    endif.
    endif.
    Consolidate
    sort i_ekko by ebeln.
    sort i_ekpo by ebeln ebelp.
    sort i_ekbe by ebeln ebelp.
    LOOP AT i_ekbe into wa_ekbe.
    read table i_ekko into wa_ekko with key ebeln = wa_ekbe-vbeln binary search.
    if sy-subrc = 0.
    ====>Move all the required firlds from I_EKKO to i_final  , like
    wa_final-BUKRS = wa_ekko-BUKRS.
    endif.
    read table i_ekpo into wa_ekpo with key ebeln = wa_ekbe-vbeln
    ebelp = wa_ekbe-ebelp binary search.
    if sy-subrc = 0.
    ====>Move all the required firlds from I_EKPO to i_final  , like
    wa_final-EBELP = wa_ekko-EBELP.
    wa_final-TXZ01 = wa_ekko-TXZ01.
    endif.
    ==>Also all the required fields from EKBE to final table, like
    wa_final-BELNR = wa_ekbe-BELNR.
    endloop.

  • No records when inputting new field from linked tables.

    I have linked two tables in a report.  If I use only fields from one table, no problem.  As soon as I add a field from the other table no records are pulled.  I am using the same filed "IncidentID" in both tables as a link.  If I attempt to pull the "IncidentID" from the second table no records are pulled.  There does not appear to be any key fields or indexes in either table if that helps.

    Here are the SQL queries.  The first string is without any fields from "WorkLog".  The second is after adding the field "WorkLog.Incident Number" to the form.
    SELECT "HPD_Help_Desk"."Incident Number", "HPD_Help_Desk"."Reported Date", "HPD_Help_Desk"."Direct Contact Site", "HPD_Help_Desk"."Assignee", "HPD_Help_Desk"."Status", "HPD_Help_Desk"."Last Modified Date", "HPD_Help_Desk"."Description", "HPD_Help_Desk"."Priority"
    FROM   "HPD:Help Desk" "HPD_Help_Desk"
    WHERE  "HPD_Help_Desk"."Status"='Pending' AND ("HPD_Help_Desk"."Assignee"='Debbie Kiolbasa' OR "HPD_Help_Desk"."Assignee"='John L King' OR "HPD_Help_Desk"."Assignee"='Ligaya Plumlee' OR "HPD_Help_Desk"."Assignee"='Ryan Keeler')
    ORDER BY "HPD_Help_Desk"."Assignee"
    SELECT "HPD_Help_Desk"."Incident Number", "HPD_Help_Desk"."Reported Date", "HPD_Help_Desk"."Direct Contact Site", "HPD_Help_Desk"."Assignee", "HPD_Help_Desk"."Status", "HPD_Help_Desk"."Last Modified Date", "HPD_Help_Desk"."Description", "HPD_Help_Desk"."Priority", "HPD_WorkLog"."Incident Number"
    FROM   "HPD:Help Desk" "HPD_Help_Desk" INNER JOIN "HPD:WorkLog" "HPD_WorkLog" ON ("HPD_Help_Desk"."Incident Number"="HPD_WorkLog"."Incident Number") AND ("HPD_Help_Desk"."InstanceId"="HPD_WorkLog"."InstanceId")
    WHERE  "HPD_Help_Desk"."Status"='Pending' AND ("HPD_Help_Desk"."Assignee"='Debbie Kiolbasa' OR "HPD_Help_Desk"."Assignee"='John L King' OR "HPD_Help_Desk"."Assignee"='Ligaya Plumlee' OR "HPD_Help_Desk"."Assignee"='Ryan Keeler')
    ORDER BY "HPD_Help_Desk"."Assignee"
    BTW - The "Left Outer Join" receives the errors noted in above post whereas the default "Inner Join" just comes back with empty records.
    Unable to use the third party tools due to restrictions on loading software.  Also we are unable to access the lower level database.
    Thanks

  • Regarding hierarchy creation from sql tables using db / ud connect

    bw version 3.0 upgrading to 7.0
    sql version 2005.
    we had built a sql data mart which is being accesses by a number of reporting tools. BI is one of the systems connected to it. My requirement is to upload hierarchies like customer from the sql data mart in to BW.
    The sql tables are in a denormalized format like this,
    EMPLOYEE_ID LAST_NAME                 MANAGER_ID      LEVEL
            101 Kochhar                          100                             1
            108 Greenberg                        101                            2
            109 Faviet                           108                                3
    They say that all third party reporting tools will recognize the above format and it universal. <b>I wanted to know is there any setting in bw that will allow extraction of hierarchies from the above table format ? if not I can only think of arranging data in the format of BW transfer structure, similar to flat file load.</b>
    I want to know can I upload hierarchies from sql tables or should I create flat files from tables ?
    Inputs will be awarded points.
    Message was edited by:
            aravind sam

    generate datasource? see if this can help..
    RSA1-> SOURCE SYSTEM-> SELECT YOUR SOURCE SYSTEM-> RIGHT CLICK-> GENERATE SOURCE SYSTEM.
    Also check:
    DB connect ORACLE - table name not found
    Re: Bw With ORacle
    Datasource in DB Connect
    and OSS Notes: 518241
    assign points if useful ***
    Thanks,
    Raj

  • How to get only column names from different tables as single table columns

    Hi All,
       I have one requirement in which we want only column names from different tables.
    for example :
     I have three tables T1 ,T2, T3 having
      col1 clo2 clo3 -->  T1 , 
      col3 col5 ,clo6 --> T2 ,
      Clo6 col8 col9 --> T3
    columns i want to get only all  Column names from all table as single Resultset not any data from that how can i get that empty resultset 
    because this empty result i want to bind in datagridview(front end) as Empty resultset 
    Please tell me anyways to do this
    Niraj Sevalkar

    If I understand you want an empty result set, just with metadata. SET FMTONLY do the trick:
    SET FMTONLY ON
    SELECT Col1, Col2, Col3, ....., Coln
    FROM
    T1 CROSS JOIN T2 CROSS JOIN T3
    SET FMTONLY OFF
    Another alternative is to include an imposible contition
    SELECT Col1, Col2, Col3, ....., Coln
    FROM
    T1 CROSS JOIN T2 CROSS JOIN T3
    WHERE 1 = 0
    If you are using a SqlDataAdapter in your client application. You can use the FillSchema method. the select command may be any select statement that returns the columns you want. Under the covers FillSchema will call SET FMTONLY ON.
    If you are using SqlCommand.ExecuteReader you can pass SchemaOnly to CommandBehavior argument. SET FMTONLY ON is called under the covers. Again the select command may be any select statement that returns the columns you want.
    "No darás tropezón ni desatino que no te haga adelantar camino" Bernardo Balbuena

  • Pull data from SQL Table and display it in mail

    I have a requirement to pull the data from SQL table and send it in email.  Currently I am sending the hard coded info in email but is it possible to pull some data from SQL Table and than format it and send it across in the same email? 
    Can you guide me with steps on this.
    Neil

    There are several ways to do this.  First is to populate a file in a data flow and then send that as an attachment in the send mail task. 
    As far as including the results in the email body this becomes a bit trickier.  To use a variable you would need to use an SSIS variable type of
    Object, this is similar to a collection in .NET.  The problem once the object is populated is that it isn't like a readable result set, but again more like an array or a collection.  There is no native method to take the object variable and
    specify .ToString() or cast its results as text.  You would need to iterate through each row and append it to another variable of type string, this could be done with a script task or ForEach container.
    Also you mentioned formatting the results.  What type of formatting were you looking for.  A limitation of the SMTP send mail task is that the message body doesn't support HTML so if you were looking at creating a table within the mail body you
    would have to use a script task or a custom component
    David Dye My Blog

  • SAP GRC 10.1 AMF No data selected when adding duplicate fields from separate tables for configurable data sources

    Hi There,
    In SAP GRC 10.0, our team had an issue where we could not add duplicate fields from separate table (see ERROR: Select Currency/UoM field for the selected analyzed fields). This was resolved by the SAP Note 1904313/ 1904314 (http://service.sap.com/sap/support/notes/1904313).
    We upgraded our system to SAP GRC 10.1 SP05 and could now add the duplicate fields from separate tables. SAP Note 1904313/ 1904314 was part of SAP GRC 10.1 SP03 so it makes sense that we, in a higher version (SP05), would be able to do this.
    The issue now is when we add the duplicate fields from different tables and run the Ad-hoc Query to test if the data source works correctly, the No Data Selected warning persists. This means that the data source provides no data for analysis, which is required to write our business rules.
    Below is an example:
    Basic data source with just one currency reference field EBAN-WAERS.
    When you run the Ad-Hoc Query you receive data.
    Basic data source with second currency reference field EKKO-WAERS.
    When you run the Ad-Hoc Query no data is found.
    Please also make reference to the following thread logged by my colleague (ERROR: Select Currency/UoM field for the selected analyzed fields)
    Any assistance to receive data with duplicate fields from separate tables will be highly appreciated.
    Thanking you in advance.
    Regards
    Gary Khan

    Hi
    following are the  error messages from dump
    hrtText
       There is already a line with the same key.
    hat happened?
       Error in ABAP application program.
       The current ABAP program "SAPLCKMS" had to be terminated because one of the
       statements could not be executed.
       This is probably due to an error in the ABAP program.
    rror analysis
       You wanted to add an entry to table "\FUNCTION-POOL=CKMS\DATA=T_DYN_CKMLCR",
        which you declared
       with a UNIQUE KEY. However, there was already an entry with the
       same key.
       This may have been in an INSERT or MOVE statement, or within a
       SELECT ... INTO statement.
       In particular, you cannot insert more than one initial line into a
       table with a unique key using the INSERT INITIAL LINE... statement.
    rigger Location of Runtime Error
       Program                                 SAPLCKMS
       Include                                 LCKMSF01
       Row                                     226
       Module type                             (FORM)
       Module Name                             DYNAMIC_PERIOD_CLOSING
    Source code where dump ocured
    222
    223           APPEND ht_ckmlpp TO t_add_ckmlpp.
    224           APPEND LINES OF ht_ckmlcr TO t_add_ckmlcr.
    225           INSERT ht_ckmlpp INTO TABLE t_dyn_ckmlpp.
    >>>>           INSERT LINES OF ht_ckmlcr INTO TABLE t_dyn_ckmlcr.
    227         ENDWHILE.
    Also I guess there is problem with material ledger in R/3 side
    I have never worked on material ledger before so dont hav idea of Tcode and tables in SAP R/3 for material ledger.
    Thanks
    Navneet

  • Read contents of changing fields from internal table

    Hi Folks,
    Please help me in my query below:
    Consider there is a Z-table with two fields TABNAM and FIELD having values KNA1 and NAME1 respectively.
    In my report I have fetched entries for customers from KNA1. Now based on the field from Z-table I want to populate a variable suppose V_FREE_VAR with the value from KNA1 table.
    Here V_FREE_VAR is of CHAR200 so that it accomodate all types of values from KNA1.
    The value of Z-table FIELD can change daily i.e next day the value may be PSTLZ.
    So how can I read the particular field from internal table as the field to be read is dynamic.
    Note: using case is not feasible.
    Thanks in advance.
    Regards,
    Shardul

    @Hartmut P
    As Rob said i want to get the value of the field from internal table. the code is something like this.
    I_KNA1 contains records for customers.
    Suppose values of Z-table are in internal table I_TEMP_TABLE.
    Entries in I_TEMP_TABLE are as follows
    TABNAME      FIELDNAME
    KNA1                 NAME1
    The value of FIELNAME in Z-table can be changed
    Loop at I_TEMP_TABLE into WA_TEMP_TABLE.
    Read I_KNA1 into WA_KNA1 with key KUNNR = '0001002234'.
    IF SY-SUBRC EQ 0.
       CASE WA_TEMP_TABLE-FIELDNAME.
            WHEN 'NAME1'.
                 V_VAR = WA_KNA1-NAME1.
             WHEN 'PSTLZ'
                  V_VAR = WA_KNA1-PSTLZ.
    ENDIF.
    But using case is not appropriate as KNA1 contains 176 fields.

  • I need to add a single field from with_item table . need to write select query with reference to company code , account doc no , fiscal year

    I need to add a single field from with_item table . need to write select query with reference to company code , account doc no , fiscal year

    Hi Arun ,
    Can you explain little bit more ??
    what is account doc no? 
    what are the transactions should be displayed in your output??
    -Rajesh N

  • How to fetch only WebI reports from the repository

    How to fetch only WebI reports from the repository, where in we have Deski reports also in the repository.. any macro??

    here is the query to fetch only webi reports:
    Open Administration Launchpad (.Net / Java) from:
    Start >> All Programs >> BusinessObjects XI Release 2 >> BusinessObjects Enterprise >
    Click on the 'Query Builder' under 'Administration Tools' on the left pane.
    Logon to Query Builder using Enterprise Administrator credentials.
    Run the following query for Web Intelligence Reports:
    SELECT SI_ID, SI_NAME, SI_OWNER FROM CI_INFOOBJECTS WHERE SI_KIND='WEBI'
    Thanks,
    Srikanth.

  • Drop down in the selection for the field from the table

    Hi.
    i want to put the drop down for the field from the table fo which i dont know the number of entries for the field zregion1 of the table zbwcntry.
    please tell me how to use the function module and what could be the line of codes.
    the drop down is for the select option on the slection screen of the classical report.
    please help .

    HI,
    Check below code..it may help you.
    REPORT Zbunu .
    TYPES :BEGIN OF STR ,
           MATNR TYPE MATNR ,
           END OF STR .
    DATA : ITAB TYPE TABLE OF STR WITH HEADER LINE,
           VAR TYPE MARA-MATNR .
    PARAMETERS : S_MATNR TYPE MATNR ,
                  P_MATNR TYPE MATNR.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR S_MATNR .
    SELECT MATNR FROM MARA INTO
    CORRESPONDING FIELDS OF TABLE ITAB UP TO 1000 ROWS.
    CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
      EXPORTING
      DDIC_STRUCTURE         = ' '
        retfield               = 'MATNR'
      PVALKEY                = ' '
       DYNPPROG               = SY-CPROG
       DYNPNR                 = SY-DYNNR
       DYNPROFIELD            = 'S_MATNR'
      STEPL                  = 0
      WINDOW_TITLE           =
      VALUE                  = ' '
       VALUE_ORG              = 'S'
      MULTIPLE_CHOICE        = ' '
      DISPLAY                = 'X'
      CALLBACK_PROGRAM       = ' '
      CALLBACK_FORM          = ' '
      tables
        value_tab              = ITAB
      FIELD_TAB              =
      RETURN_TAB             =
      DYNPFLD_MAPPING        =
    EXCEPTIONS
       PARAMETER_ERROR        = 1
       NO_VALUES_FOUND        = 2
       OTHERS                 = 3
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    Regards
    Ansumesh

Maybe you are looking for