Trouble using the "into" keyword in a select statement

I was able to run the below query fine:
SELECT QTTYP.Qt_Grp, 
CFQR.ReferralCode, 
CFQR.RecKey, 
Count(CFQR.RecKey) AS Cnt
FROM [HR_DEV_DM].[CFQ_TEST].CFQ_Referrals as CFQR 
INNER JOIN [HR_DEV_DM].[CFQ_TEST].t_Qt_Typs as QTTYP 
ON CFQR.QuoteType = QTTYP.Qt_Grp
WHERE (((CFQR.QuoteType) Not In ('AUTO/CYCLE','COMMERCIAL','CYCLE')) 
AND ((CFQR.QuoteDate)>=DateAdd("m",-15,CONVERT (date, GETDATE())))
AND ((CFQR.RecCntdAsRefrl)=1))
GROUP BY QTTYP.Qt_Grp, 
CFQR.ReferralCode, 
CFQR.RecKey, 
CFQR.RecChangeID
HAVING (((Count(CFQR.RecKey))>1) AND ((CFQR.RecChangeID) Is Null)) 
OR (((Count(CFQR.RecKey))>1) 
AND ((CFQR.RecChangeID) Not In (1035)))
ORDER BY QTTYP.Qt_Grp, CFQR.RecKey;
I am trying to add the output columns into a temp table. But when I add the "into" statement, as shown below, it gives me errors:
SELECT QTTYP.Qt_Grp, 
CFQR.ReferralCode, 
CFQR.RecKey, 
Count(CFQR.RecKey) AS Cnt
FROM [HR_DEV_DM].[CFQ_TEST].CFQ_Referrals as CFQR 
into I_Dup_RecKey_Check_01
INNER JOIN [HR_DEV_DM].[CFQ_TEST].t_Qt_Typs as QTTYP 
ON CFQR.QuoteType = QTTYP.Qt_Grp
WHERE (((CFQR.QuoteType) Not In ('AUTO/CYCLE','COMMERCIAL','CYCLE')) 
AND ((CFQR.QuoteDate)>=DateAdd("m",-15,CONVERT (date, GETDATE())))
AND ((CFQR.RecCntdAsRefrl)=1))
GROUP BY QTTYP.Qt_Grp, 
CFQR.ReferralCode, 
CFQR.RecKey, 
CFQR.RecChangeID
HAVING (((Count(CFQR.RecKey))>1) AND ((CFQR.RecChangeID) Is Null)) 
OR (((Count(CFQR.RecKey))>1) 
AND ((CFQR.RecChangeID) Not In (1035)))
ORDER BY QTTYP.Qt_Grp, CFQR.RecKey;
Errors:
Msg 156, Level 15, State 1, Line 7
Incorrect syntax near the keyword 'into'.
Msg 102, Level 15, State 1, Line 11
Incorrect syntax near 'CFQR'.
Msg 102, Level 15, State 1, Line 18
Incorrect syntax near 'Count'.
Msg 102, Level 15, State 1, Line 19
Incorrect syntax near 'Count'.
Please help.....

You have put INTO into the wrong place :
SELECT QTTYP.Qt_Grp,
CFQR.ReferralCode,
CFQR.RecKey,
Count(CFQR.RecKey) AS Cnt
into I_Dup_RecKey_Check_01
FROM CFQ_Referrals as CFQR
INNER JOIN t_Qt_Typs as QTTYP
ON CFQR.QuoteType = QTTYP.Qt_Grp
WHERE (((CFQR.QuoteType) Not In ('AUTO/CYCLE','COMMERCIAL','CYCLE'))
AND ((CFQR.QuoteDate)>=DateAdd("m",-15,CONVERT (date, GETDATE())))
AND ((CFQR.RecCntdAsRefrl)=1))
GROUP BY QTTYP.Qt_Grp,
CFQR.ReferralCode,
CFQR.RecKey,
CFQR.RecChangeID
HAVING (((Count(CFQR.RecKey))>1) AND ((CFQR.RecChangeID) Is Null))
OR (((Count(CFQR.RecKey))>1)
AND ((CFQR.RecChangeID) Not In (1035)))
ORDER BY QTTYP.Qt_Grp, CFQR.RecKey;

Similar Messages

  • I'm having trouble using the iTunes and Apps store because i can't register my Nigerian mastercard. What should i do. i'm trying to register it in the Nigerian iTunes store.

    I'm having trouble using the iTunes and Apps store because i can't register my Nigerian mastercard. What should i do. i'm trying to register it in the Nigerian iTunes store.

    Is this a new Apple iD? If it is, and you have already set it up, then you have two options:
    1.     Temporarily put a Credit Card or Gift Card on the account to download the free app. If you put a credit card, then once you have downloaded the app, you should be able to go into your Account preferences and change the payment option to = None.
    2.     You can download the fee App, and then set up a new Apple ID.
    Cheers,
    GB

  • How to reference a class without using the new keyword

    I need to access some information from a class using the getter, but I don't want to use the new keyword because it will erase the information in the class. How can I reference the class without using the new keyword.
    ContactInfo c = new ContactInfo(); // problem is here because it erases the info in the class
    c.getFirstName();

    quedogf94 wrote:
    I need to access some information from a class using the getter, but I don't want to use the new keyword because it will erase the information in the class. How can I reference the class without using the new keyword.
    ContactInfo c = new ContactInfo(); // problem is here because it erases the info in the class
    c.getFirstName();No.
    Using new does not erase anything. There's nothing to erase. It's brand new. It creates a new instance, and whatever that constructor puts in there, is there. If you then change the contents of that instance, and you want to see them, you have to have maintained a reference to it somewhere, and access that instance's state through that reference.
    As already stated, you seem to be confused between class and instance, at the very least.
    Run this. Study the output carefully. Make sure you understand why you see what you do. Then, if you're still confused, try to rephrase your question in a way that makes some sense based on what you've observed.
    (And not that accessing a class (static) member through a reference, like foo1.getNumFoos() is syntactically legal, but is bad form, since it looks like you're accessing an instance (non-static) member. I do it here just for demonstration purposes.)
    public class Foo {
      private static int numFoos; // class variable
      private int x; // instance varaible
      public Foo(int x) {
        this.x = x;
        numFoos++;
      // class method
      public static int getNumFoos() {
        return numFoos;
      // instance method 
      public int getX() {
        return x;
      public static void main (String[] args) {
        System.out.println ("Foo.numFoos is " + Foo.getNumFoos ());
        System.out.println ();
        Foo foo1 = new Foo(42);
        System.out.println ("Foo.numFoos is " + Foo.getNumFoos ());
        System.out.println ("foo1.numFoos is " + foo1.getNumFoos ());
        System.out.println ("foo1.x is " + foo1.getX ());
        System.out.println ();
        Foo foo2 = new Foo(666);
        System.out.println ("Foo.numFoos is " + Foo.getNumFoos ());
        System.out.println ("foo1.numFoos is " + foo1.getNumFoos ());
        System.out.println ("foo1.x is " + foo1.getX ());
        System.out.println ("foo2.numFoos is " + foo2.getNumFoos ());
        System.out.println ("foo2.x is " + foo2.getX ());
        System.out.println ();
    }

  • Trouble using the Web-based utility

    I have a WRT54G wireless router, V8, firmware 8.0.0. It is Ethernet-connected to a Windows Vista machine running SP1.
    I am having trouble using the Web-based utility. I can access it but cannot make any changes.  For instance, if I change the settings on the Setup page and click "save", I get a "This webpage is not available"
    I tried updating the firmware and got the same message. Disabling my personal firewall has no effect. Resetting the router from the button on its rear panel has no effect. I tried using with both Windows IE and Google Chrome browsers and got the same result.
    I have been using this router without problem for months using a a Windows XP machine. This problem may be associated with my changing it to the current Windows Vista machine. I no longer have the Windows XP machine.
    Please help me. Thank you and Happy New Year!
    - tom 

    I spent a full day unsuccessfully trying to make it work, including numerous Linksys utilities downloaded from the site. I could not conjure any support on Linksys chat, and the live body on the Linksys tech support line wanted to charge me $29 for his help.
    I finally succeeded by purchasing and installing a Netgear wireless router ($44, Staples) that came up flawlessly the first time. The Linksys device is in my trash. 

  • Hi, I am having trouble using the smooth tool on a logo that I created. I have watched tutorials and something isn't working for me. When trace with the smooth the line just disappears and doesn't smooth anything out. Please help.

    Hi, I am having trouble using the smooth tool on a logo that I created. I have watched tutorials and something isn't working for me. When trace with the smooth the line just disappears and doesn't smooth anything out. Please help.

    Sorry, that's Monika with a k
    On Tue, Nov 18, 2014 at 2:26 PM, Monika Gause <[email protected]>

  • How to add a dummy row in the result set of a SELECT statement.

    Hello Everyone -
    I have requirment to add a dummy row in the result set of a SELECT statement.
    For e.g. lets say there is a table Payment having following colums:
    Payment_id number
    status varchar2(10)
    amount number
    payment_date date
    so here is the data :-
    Payment_id Status Amount payment_date
    1 Applied 100 12/07/2008
    2 Reversed 200 01/ 06/2009
    3 Applied 300 01/ 07/2009
    Here is my SQL
    Select * form payment where payment_date >= 01/01/2009
    Output will be
    2 Reversed 200 01/ 06/2009
    3 Applied 300 01/ 07/2009
    My desired output is below
    2 Reversed 200 01/ 06/2009
    3 Applied 300 01/ 07/2009
    2 Reversed -200 01/ 06/2009 ------(Dummy Row)
    Thrid row here is the dummy row which I want to add when status is "Reversed"
    I would be very thankful for any kind of help in this regard ...
    Thanks,
    Gaurav

    Cartesion joining against a dummy table is a useful method of creating a dummy row:
    with my_tab as (select 1 cust_id, 1 Payment_id, 'Applied' Status, 100 Amount, to_date('12/07/2008', 'mm/dd/yyyy') payment_date from dual union all
                    select 1 cust_id, 2 Payment_id, 'Reversed' Status, 200 Amount, to_date('01/06/2009', 'mm/dd/yyyy') payment_date from dual union all
                    select 1 cust_id, 3 Payment_id, 'Applied' Status, 300 Amount, to_date('01/06/2009', 'mm/dd/yyyy') payment_date from dual union all
                    select 2 cust_id, 1 Payment_id, 'Applied' Status, 100 Amount, to_date('12/07/2008', 'mm/dd/yyyy') payment_date from dual union all
                    select 2 cust_id, 2 Payment_id, 'Reversed' Status, 200 Amount, to_date('01/05/2009', 'mm/dd/yyyy') payment_date from dual union all
                    select 2 cust_id, 3 Payment_id, 'Applied' Status, 300 Amount, to_date('01/06/2009', 'mm/dd/yyyy') payment_date from dual union all
                    select 2 cust_id, 4 Payment_id, 'Reversed' Status, -400 Amount, to_date('01/06/2009', 'mm/dd/yyyy') payment_date from dual union all
                    select 2 cust_id, 5 Payment_id, 'Applied' Status, 500 Amount, to_date('01/07/2009', 'mm/dd/yyyy') payment_date from dual),
                    --- end of mimicking your table
          dummy as (select 'Reversed' col1, 1 rn from dual union all
                    select 'Reversed' col1, 2 rn from dual)
    select mt.cust_id,
           mt.payment_id,
           mt.status,
           decode(dummy.rn, 2, -1*mt.amount, mt.amount) amount,
           mt.payment_date
    from   my_tab mt,
           dummy
    where  mt.status = dummy.col1 (+)
    order by mt.cust_id, mt.payment_id, dummy.rn nulls first;
    CUST_ID     PAYMENT_ID     STATUS     AMOUNT     PAYMENT_DATE
    1     1     Applied     100     07/12/2008
    1     2     Reversed     200     06/01/2009
    1     2     Reversed     -200     06/01/2009
    1     3     Applied     300     06/01/2009
    2     1     Applied     100     07/12/2008
    2     2     Reversed     200     05/01/2009
    2     2     Reversed     -200     05/01/2009
    2     3     Applied     300     06/01/2009
    2     4     Reversed     -400     06/01/2009
    2     4     Reversed     400     06/01/2009
    2     5     Applied     500     07/01/2009Edited by: Boneist on 07-Jan-2009 23:10
    NB. You may have to mess around with the ordering if that's not come back in the order you wanted. You didn't mention what the rules were for any expected ordering though, so I've made up my own *{;-)
    Also, I added an identifier (cust_id) to differentiate between different sets of payments, since that's usually the case. Remove that if it's not applicable for your case.

  • Using temporary tablespace for sort in select statement without spacifying

    how can i use some particular temporary tablespace in select statement for sording without allocating any temporary tablespace to that user

    Try to set for the current session the in memory sorting space to 0 before running your query:
    SQL> alter session set sort_area_size = 0;The query should use the temporary tablespace.
    Message was edited by:
    Pierre Forstmann

  • How to edit the records value fetched by select statement query in sqldever

    How to edit the records value fetched by select statement query in sqldever 2.1.1.
    EX-
    SELECT * FROM emp WHERE ename like 'Jaga%'
    Edited by: user9372056 on Aug 31, 2010 2:16 AM

    Hi,
    Although some forum members may be using that tool, there is still a dedicated forum for SQL Developer.
    SQL Developer
    Maybe your chances are better there.
    Regards
    Peter

  • Use two secondary indexes in a select statement

    hi, i want to use two secondary indexes in a select statement.
    how can i do it?

    Hello,
    To do it use the WHERE stm in the same order as the secondary stm is on SE11....To check if the index is used go to tcode ST05.
    example
    select * from ztable
    WHERE BUKRS EQ 'BUK1' AND
                 ZFIELD EQ 'BOY'.
    on se11 on the ZTABLE indexes setion must have a secondary index with
    BUKRS and
    ZFIELD.
    BYE!!
    Hope this helps!!
    Gabriel

  • Values from a Multi-Select in the where clause of a Select statement

    I have a web page that solicits query parameters from the user.
    The selections that the user makes will populate the WHERE clause of a Select statement.
    One of the controls on the page is a multi-select control.
    When this page posts, I would like to execute a Select statement wherein the selected values from this control appear in the .. Column IN ( <list here> ) portion of the WHERE clause.
    This is an extremely common scenario, but I cannot seem to locate a how-to or message thread that addresses this specific case.
    I have an idea that it may involve dynamic SQL or Execute Immediate, but cannot seem to pin down the answer.
    Any help would be greatly appreciated!

    anonymous - As illustrated here: Re: Search on a typed in list of values
    Scott

  • How do I use the INTO word in my querys?

    Hi! I'm working with Oracle 10g and Microsoft Visual Studio 2008 (Visual C#), I connected both succesfully, now I can add data to my tables from C#, but the problem comes when I try to request data from the database, I'm trying to do that with this query: "SELECT Id_Estado, DetalleEstado FROM Estado", but it doesn't work, it shows me an error, saying that I have to put an "INTO" in my query, but, where should I put it? and in wich kind of "object" should I save the data that I'm requesting.
    I guess I have to make a query like this: "SELECT Id_Estado, DetalleEstado INTO "an object/container" FROM Estado".
    I'm new with Oracle, I hope you can help me. Thank you so much.

    I would suggest you this
    1. Create a stored function with return typer as REF CURSOR. You can create your own REF CURSOR or use the oracle supplied one i.e. SYS_REFCURSOR.
    2. Inside the function do something like this.
    create or replace function get_estado_data return sys_refcursor
    as
      pOutCursor sys_refcursor;
    begin
      open pOutCursor for
      select * from Estado;
      return pOutCursor;
    end;
    /3. Now from your C# call this function using ExicuteDataSet API and store the output in a DataSet.

  • Using the LIKE keyword in a SQL query

    Does anyone have an example using the Database Connectivity Execute Query vi and the LIKE keyword? I would like to do something like:
    SELECT TestNum, TestType FROM tests WHERE DeviceType ='Paul_AF125_Ver1' AND DeviceID = 'Test1' AND (TestType LIKE "Cyclic Voltammetry*")
    It works fine if I say LIKE "Cyclic Voltammetry" (without the *) but if I put the * in there, I get no records.
    I'm using Microsofts SQL Server Desktop Engine (comes with Access).
    Thanks,
    Paul

    Paul-
    Thank you for contacting National Instruments. I don't have an example program, but I did find some information for you.
    LIKE - similar to.
    Using the LIKE command, you can use the wildcard symbol %. To find names starting with J : names LIKE 'J%'; Ending in s ? name LIKE '%S'; You can use more than one % charactor too : names LIKE '%sam%'; Also, LIKE is not case sensitive.
    What you have written, may work if you change the wildcard syntax from * to %.
    -Erik

  • What is the use of for all entries in select statement

    what is the use of for all entries in select statement

    hi,
    FOR ALL ENTRIES is an effective way of doing away with using JOIN on two tables.
    You can check the below code -
    SELECT BUKRS BELNR GJAHR AUGDT
    FROM BSEG
    INTO TABLE I_BSEG
    WHERE BUKRS = ....
    SELECT BUKRS BELNR BLART BLDAT
    FROM BKPF
    INTO TABLE I_BKPF
    FOR ALL ENTRIES IN I_BSEG
    WHERE BUKRS = I_BSEG-BUKRS
    AND BELNR = I_BSEG-BELNR
    AND BLDAT IN SO_BLDAT.
    *******************************8
    look another example
    what is the use of FOR ALL ENTRIES
    1. INNER JOIN
    DBTAB1 <----
    > DBTAB2
    It is used to JOIN two DATABASE tables
    having some COMMON fields.
    2. Whereas
    For All Entries,
    DBTAB1 <----
    > ITAB1
    is not at all related to two DATABASE tables.
    It is related to INTERNAL table.
    3. If we want to fetch data
    from some DBTABLE1
    but we want to fetch
    for only some records
    which are contained in some internal table,
    then we use for alll entries.
    1. simple example of for all entries.
    2. NOTE THAT
    In for all entries,
    it is NOT necessary to use TWO DBTABLES.
    (as against JOIN)
    3. use this program (just copy paste)
    it will fetch data
    from T001
    FOR ONLY TWO COMPANIES (as mentioned in itab)
    4
    REPORT abc.
    DATA : BEGIN OF itab OCCURS 0,
    bukrs LIKE t001-bukrs,
    END OF itab.
    DATA : t001 LIKE TABLE OF t001 WITH HEADER LINE.
    itab-bukrs = '1000'.
    APPEND itab.
    itab-bukrs = '1100'.
    APPEND itab.
    SELECT * FROM t001
    INTO TABLE t001
    FOR ALL ENTRIES IN itab
    WHERE bukrs = itab-bukrs.
    LOOP AT t001.
    WRITE :/ t001-bukrs.
    ENDLOOP.
    Hope this helps!
    Regards,
    Anver
    <i>if hlped pls mark points</i>

  • Using if logic in the where clause of a select statement

    I have a select clause. And in the select clause there is a variable all_off_trt that can be 'Y' or 'N'.
    In the where clause I want to make it so that if a form variable is checked and all_off_trt is 'Y' then
    exclude it else if the form variable isn't checked then select it no matter what all_off_trt is.
    Is there any way to include either and if statement or a case statement within the where clause to acheive this? If not is there another way of doing it?
    Basically I am looking for a case statement like this
    case
    when all_off_trt = 'Y' and mail_para.code = 'Y' then false
    else true
    end
    Message was edited by:
    Tugnutt7

    Ok, so that really doesn't solve my problem. I have 3 different fields that I need to do that with. Each combining in a select statement to print an email list, as well as other thing limiting the where clause.
    This is currently what I have, tested and working 100%.
    cursor email_cur is
         select unique p.email,s.all_off_trt,s.all_deceased,s.no_enroll
    from participant p, trialcom t, ethics s
    where p.status='A'
    and p.surname=t.surname
    and p.initials=t.initials
    and s.trial_cd = t.tricom
    and s.centre = t.centre
    and p.email is not null
    and (t.centre in (select code from mail_parameters where user_name=user and mail_para='CENTRE')
    or 'XX' in (select code from mail_parameters where user_name=user and mail_para='CENTRE'))
    and (t.tricom in (select code from mail_parameters where user_name=user and mail_para='TRIAL')
    or 'XX' in (select code from mail_parameters where user_name=user and mail_para='TRIAL'))
    and (t.role in (select code from mail_parameters where user_name=user and mail_para='ROLE')
    or 'XX' in (select code from mail_parameters where user_name=user and mail_para='ROLE'))
    and (p.country in (select code from mail_parameters where user_name=user and mail_para='COUNTRY')
    or 'XX' in (select code from mail_parameters where user_name=user and mail_para='COUNTRY'))
    and (t.represent in (select code from mail_parameters where user_name=user and mail_para='REPRESENT')
    or 'XX' in (select code from mail_parameters where user_name=user and mail_para='REPRESENT'));
    This is in a program unit that runs when a button is clicked. At the end of that I need to add on the 3 case statements that help further narrow down the selection of emails to be printed. Then it prints the emails selected from this statement into a file. So it has to be done right in the select statement. The three table variables are the all_off_trt, all_deceased, and no_enroll. The form has 3 checkboxes. One for each, that when checked (giving the variable associated with the checkboxes a value of 'Y') excludes all emails that have a 'Y' in the coresponding table variable.

  • TS2972 How can I stop iTunes on my computer to start whenever I use the Apple TV remote to select a new program?

    Whenever I use the Apple TV remote to choose a new program, iTunes starts on my computer and starts playing from the playlist. How do I prevent that from happening?

    Your computer is picking up the remote's signal. Go into system preferences - security - general. Click on the padlock and go into advanced. Check disable remote control infrared receiver.

Maybe you are looking for

  • Open mxml from a string

    I have my menu in a xml: <MenuItem className="ProposalDetails" title="Select Proposal" openType="list" toolTip="Select Proposals and Proposal Versions" roles="60" url="selectProposalIcon" /> I want to open the className of my MenuItem when I click it

  • Has anybody used JDev 10g to write an extension to 11i e-business suite?

    We are looking to develop an application that can be called from within the menu structure of the 11i e-business suite and would like to use JDeveloper 10g. I have read that the OA Extension for JDev 9 can be used for this, but I've also read that th

  • Error messages in webdynpro

    Hi, I'm currently working on developing an ESS scenario for IT0573 Australia (Absences). For this scenario I've not used the FPM completely. The roadmap is as follows: Overview -> Detail -> Review and Save -> Confirmation. The node Detail has a sub-r

  • Data for travel management?

    i'm currently looking for the data for travel management (Financials Management & Controling --> Travel Management) in the DS server. i have been looking for it for  a few week and i still cant get the data. so does anyone have any idea on where the

  • Call to possibly undefined method addChild

    when i use addChild method in my class I got this message . Why it shows error "Call to possibly undefined method addChild"