Help Using MAX()

I am trying to run this statement
Select convert(varchar(10), Max(salesCallDate), 101)
From database
but this throws an error of Syntax error converting the varchar value 12/15/201 to a column of data type int

Are you sure your date is '12/15/201' or is it '12/15/2014' ?
Above query should work fine and you are not converting it to INT BTW.
-Vaibhav Chaudhari
Yes it should be 12/15/2014, typo.
Actually I am mistaken the error is produced on the JOIN statement
Select
a.salesCallDate,
a.CallerName,
b.PersonName,
b.PersonAddress,
b.PersonZip
from internalDB a
Inner join externalDB b
On a.SalesCallDate = Convert(varchar(10), MAX(salescalldate),101)
Group by a.salescalldate, a.callername, b.personname, b.personaddress, b.personzip
why are you converting date to varchar here? Provided SalesCallDate is of datetime type what you need is just this
Inner join externalDB b
On a.SalesCallDate >= MAX(salescalldate)
AND a.SalesCallDate < DATEADD(dd,1,MAX(salescalldate))
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
My MSDN Page
My Personal Blog
My Facebook Page

Similar Messages

  • Using max function in PL/SQL

    VERY URGENT...
    Am new to oracle...
    I've written a package that display gif images in form of histogram/bar chart. using html,
    I need to use max function to display values proportionately.
    please help. i need to complete this assignment by 2/9/00 by 10.00 am at the latest. I've half written a function but I don't know if there's a simpler way fo doing this. html enabled

    First of all Thanks to all gentlemen who replied ..many thanks ...
    Tried the ROW_NUMBER() option but still it is taking time...have given output for the query and tkprof results as well. Even when it doesn't fetch any record ( this is a valid cased because the input header id doesn't have any workflow request submitted & hence no entry in the wf_items table)..then also see the time it has taken.
    Looked at the RANK & DENSE_RANK options which were suggested..but it is still taking time..
    Any further suggestions or ideas as to how this could be resolved..
    SELECT 'Y', 'Y', ITEM_KEY
    FROM
    ( SELECT ITEM_KEY, ROW_NUMBER() OVER(ORDER BY BEGIN_DATE DESC) RN FROM
    WF_ITEMS WHERE ITEM_TYPE = 'xxxxzzzz' AND ROOT_ACTIVITY = 'START_REQUESTS'
    AND SUBSTR(ITEM_KEY,1,INSTR(ITEM_KEY,'-') - 1) = :B1
    ) T WHERE RN <= 1
    call count cpu elapsed disk query current rows
    Parse 0 0.00 0.00 0 0 0 0
    Execute 1 0.00 1.57 0 0 0 0
    Fetch 1 8700.00 544968.73 8180 8185 0 0
    total 2 8700.00 544970.30 8180 8185 0 0
    many thanks

  • I am trying to configure my SCXI-1540 card for excitation voltage and frequency using MAX - but it is not giving me that option when I click on the card and then properties​, am I looking in the wrong place?

    I am trying to configure my SCXI-1540 w/1315 card for excitation voltage and frequency using MAX - but it is not giving me that option when I click on the card and then properties, am I looking in the wrong place?
    I have LabVIEW Express 7.0 Professional - SCXI-1000 Chassiss - along with SCXI-1112, and SCXI 1520/1314 - cable to the PCI-6052E is attached to the 1520 card.
    MAX says it recognizes all the cards in the chassiss.

    Jeremy, Thanks for the reply.
    I tried to set up the system as DAQmx.
    I had MAX auto-detect the set-up - and it recognized all the cards - but did not select the 1315 accessory on the 1540 card - I had to do that manually - but in the configuration section I would select the accessory and it would deselect itself. I had to get out of the set-up and then right click on the 1540 card and click on the "Accessories" tab and select the 1315 terminal block that way.
    It didn't seem right that the system should behave that way, but I pressed onward.
    I then tried to create a new DAQmx Task
    When I create new DAQmx task and then click on Analog Input no "Position" Tab appears for me to select, all I get are:
    Analog>>Voltage
    Analog>>Temperature
    Ana
    log>>Strain
    Analog>>Current
    Analog>>Resistance
    Analog>>Frequency
    Analog>>Custom Voltage with Excitation
    Do you think there might be something wrong with either my hardware or perhaps my configuration that is not allowing it to recognize the 1540/1315 in DAQmx?
    I had included the system report of what programs I am using, etc. as attached file nireport.txt
    After the DAQmx did not work I tried installing everything as Traditional DAQ and it did let me set-up the 1540 Card with Excitation Voltage and Frequency and gain - I then went in to the VI that I had built and tried to use the Express DAQ Assisant to read the channel that I am connected to on the 1315/1540 - when I try to use DAQ Assistant it gives me an error saying that "Device not available in NI-DAQmx. It is possible that the device is being use by traditional NI-DAQ"
    Which I guess it is since both configurations are now set-up in MAX.
    I would PREFER to use the DAQmx set-up, but I am confused as to WHY it won
    't come up with
    Analog input>>POSITION>>LVDT
    When I try to create a new DAQmx task.
    Thanks for the help so far! As you can probably tell I am new at this.
    Ryan
    Attachments:
    nireport.txt ‏2 KB

  • How to use MAX function in SSAS MDX Query

    I want to run this Query with MAX Condition on LAST_DATA_UPDATE Column .

    Hi Ashishsingh,
    According to your description, you want to know how to use MAX function in SQL Server Analysis Services MDX Query, right? In this case, please refer to the link below which describe the syntax and sample of MDX function.
    http://technet.microsoft.com/en-us/library/ms145601.aspx
    http://www.mdxpert.com/Functions/MDXFunction.aspx?f=64
    Hope this helps.
    Regards,
    Charlie Liao
    TechNet Community Support

  • Oracle:how to use max() function in case expression

    how to use max() function in case expression, Please explain with any example

    Hope this helps and should be self explanatory
    with t as
    (select 1 col,100 col2 from dual union
    select 2 ,100 from dual union
    select 2 ,200 from dual union
    select 3,100  from dual union
    select 3,200  from dual  )
    select col, case when max(col2)=100 then 'with 100 range'
    when  max(col2)=200 then 'with 200 range' end  from t group by col

  • Performance issue with using MAX function in pl/sql

    Hello All,
    We are having a performance issue with the below logic wherein MAX is being used in order to get the latest instance/record for a given input variable ( p_in_header_id).. the item_key is having the format as :
    p_in_header_id - <number generated from a sequence>
    This query to fetch even 1 record takes around 1 minutes 30 sec..could someone please help if there is a better way to form this logic & to improve performance in this case.
    We want to get the latest record for the item_key ( this we are getting using MAX (begin_date)) for a given p_in_header_id value.
    Query 1 :
    SELECT item_key FROM wf_items WHERE item_type = 'xxxxzzzz'
    AND SUBSTR (item_key, 1, INSTR (item_key, '-') - 1) =p_in_header_id
    AND root_activity ='START_REQUESTS'
    AND begin_date =
    (SELECT MAX (begin_date) FROM wf_items WHERE item_type = 'xxxxzzzz'
    AND root_activity ='START_REQUESTS'
    AND SUBSTR (item_key, 1, INSTR (item_key, '-') - 1) =p_in_header_id);
    Could someone please help us with this performance issue..we are really stuck because of this
    regards

    First of all Thanks to all gentlemen who replied ..many thanks ...
    Tried the ROW_NUMBER() option but still it is taking time...have given output for the query and tkprof results as well. Even when it doesn't fetch any record ( this is a valid cased because the input header id doesn't have any workflow request submitted & hence no entry in the wf_items table)..then also see the time it has taken.
    Looked at the RANK & DENSE_RANK options which were suggested..but it is still taking time..
    Any further suggestions or ideas as to how this could be resolved..
    SELECT 'Y', 'Y', ITEM_KEY
    FROM
    ( SELECT ITEM_KEY, ROW_NUMBER() OVER(ORDER BY BEGIN_DATE DESC) RN FROM
    WF_ITEMS WHERE ITEM_TYPE = 'xxxxzzzz' AND ROOT_ACTIVITY = 'START_REQUESTS'
    AND SUBSTR(ITEM_KEY,1,INSTR(ITEM_KEY,'-') - 1) = :B1
    ) T WHERE RN <= 1
    call count cpu elapsed disk query current rows
    Parse 0 0.00 0.00 0 0 0 0
    Execute 1 0.00 1.57 0 0 0 0
    Fetch 1 8700.00 544968.73 8180 8185 0 0
    total 2 8700.00 544970.30 8180 8185 0 0
    many thanks

  • Cannot use MAX function in PS Query

    I am trying to use Query to select the max ( effdt ) from a table.
    First, I use the 'Criteria' page to have
    (1) Expression 1 = A.EFFDT - Effective Date, (2) Condition type = equal to, (3) Expression 2 = Subquery
    Then the Subquery is:
    (1) In the 'Field' page, I choose field E.EFFDT - Effective Date, (2) then click on 'EDIT', (3) then click on 'Max', (4) then click on 'OK' button
    I then get this message: 'This field is an aggregate field but is being used in non-having criteria.(139,136). The query may fail if this is not corrected'
    And as i try run anyway this query, i get this message:
    SQL error. Stmt #: 5653 Error Position: 349 Return: 934 - ORA-00934: group function is not allowed here
    A SQL error occurred. Please consult your system log for details.
    Error in running query because of SQL Error, Code=934, Message=ORA-00934: group function is not allowed here (50,380)
    NOTE: This max sql would work if i run using SqlPlus
    How can i get Query to use max( effdt ) ?
    Any clue anyone ? THANKS

    Yes Using it as MAX is OK.
    Problem is once you use it as MAX of a field, it wouln't allow this field for you to use it anymore.
    A workaround i found that helped is to use the expression let's say 'MAX( a.JOB )' and use this as field.
    This way, the system will allow me to use the JOBCODE field.
    Thank you for all your helps as it leads me to the soln.

  • Performance issue in SQL while using max

    Hi
    I have log table which desired changed date. if any transaction entered for the changed date and less, then the name and location should be shown based on change log table. if change log entry has two values for a same date for a customer then need to show the max value for the row.
    Log table
    ID   CUSTOMER_ID                NAME        LOCATION      CHANGED_DATE
    1          1                      sar          boston          11-1-13
    2          2                      var          chn             12-1-13
    3          1                      gar          boston          13-1-13
    4          1                      nar          boston          13-1-13
    Transaction table
    ID            CUSTOMER_ID               DATE         QTY  
    1                 1                    11-1-13       10
    2                 2                    12-1-13        9
    3                 1                    10-1-13        8
    4                 1                    13-1-13        7
    Required Result
    ID            CUSTOMER_ID                 NAME               LOCATION            DATE         QTY  
    1                 1                       sar                  boston            11-1-13       10
    2                 2                       var                  chn               12-1-13        9
    3                 1                       sar                  boston            10-1-13        8
    4                 1                       nar                  boston            13-1-13        7I got the above result using the max when multiple log entry for same date. but if use max value i got performance issue when log entry table has more entries.
    can you help me in this?
    Edited by: Tsk on Apr 23, 2013 1:12 AM

    How do I ask a question on the forums?
    SQL and PL/SQL FAQ

  • How to Use MAX condition using Query Report

    Hi SAP Abap Expert,
    Can we use the MAX condition in Query Report (SQ01/SQ02) ?
    I have created one sample query using table VBRP and VBRK then i need to use max condition to get the MAX record in VBELN.
    Please Help ???

    Hi Ashishsingh,
    According to your description, you want to know how to use MAX function in SQL Server Analysis Services MDX Query, right? In this case, please refer to the link below which describe the syntax and sample of MDX function.
    http://technet.microsoft.com/en-us/library/ms145601.aspx
    http://www.mdxpert.com/Functions/MDXFunction.aspx?f=64
    Hope this helps.
    Regards,
    Charlie Liao
    TechNet Community Support

  • I want to configure the 7330 motion controller without using MAX

    I am new to labview and I have a project where I have to configure the 7330 motion controller without using MAX. What do I need to do to get started doing so?
    Thanks for the help!
    nw2labview

    Hi,
    There are several VI's that are included with the motion driver for configuring your controller.  They are located on the function pallete under Vision and Motion>>Ni-Motion>>Axis Configuration.  Using these VI's you will be able to configure your axis.  But why don't you want to use MAX?  If you are new to LabVIEW I would suggest configuring and testing your motor in MAX first before you start programing.  Once you have it working there you may want to look at several of the examples such as Simple One-Axis Move.vi.  I hope this helps.
    GG

  • Need help with MAX function to return values

    I am trying to create a report to return slow moving inventory data. One of the requests is that it return only the latest date that an item transacted upon. One sheet will show the last receipt date for a part, another will show the last time a part was issued or shipped on a sales order.
    The hiccup is that it is returning every single last time that an item was received, and every single last issuance of the material (on the second sheet) of items on hand.
    Could someone help me to define the max value function? As listed below, and many variations, the sheet comes up with no data or corrupt dates.
    MAX(Transaction Date MAX) OVER(PARTITION BY Material Transactions.Item ORDER BY Material Transactions.Item )
    Still returns both the following when in reality I just want the one with the most recent date (April 2010).
    100034     BNDSCE-105 - QUALITY BEARINGS OR EQUIVILANT     A400M     AB01D..     $0.00     WIP component issue     11-Sep-2009     -3
    100034     BNDSCE-105 - QUALITY BEARINGS OR EQUIVILANT     A400M     AD01D..     $0.00     WIP component issue     13-Apr-2010     -16
    Thank you for your assistance.
    Becka

    Hi Becka
    It does look correct. When I look at your data I can see 2 different items:
    100034 BNDSCE-105 - QUALITY BEARINGS OR EQUIVILANT A400M AB01D.. $0.00 WIP component issue 11-Sep-2009 -3
    100034 BNDSCE-105 - QUALITY BEARINGS OR EQUIVILANT A400M AD01D.. $0.00 WIP component issue 13-Apr-2010 -16
    One is AB01D and the other being AD01D. Is this expected?
    To get the right date you might want to PARTITION BY the BNDSCE-105 which might be the Item Number?
    If you can get your calculation to return the correct date then you next need to put in a new condition where the Transaction Date = MAX Transaction Date
    One part of the function that I would question is the use of MAX in both parts like this: MAX(Transaction Date MAX). You might be better just using MAX(Transaction Date) OVER ......
    Does this help?
    Best wishes
    Michael

  • Using MAX on an INNER JOIN

    Is there any way to use MAX on an INNER JOIN???
    I am getting the MAX Date row on a previous INNER JOIN and then I want to use that result row to get an Account Balance. I know it's hard to explain without the SQL but I'll try...
    So I want the MAX(BILLHDR.dt_bill)'s Account Balance...
    SELECT PYMTADJ.ky_payment_adjustment,
    PYMTADJ.ky_enroll,
    PYMTADJ.dt_payment_adjustment,
    PYMTADJ.at_payment_adjustment,
    MAX(BILLHDR.dt_bill) Last_Bill_Date,
    MAX(BILLHDR.dt_reading_from) "Last Bill Period From Date",
    MAX(BILLHDR.dt_reading_to) "Last Bill Period To Date",
    BILLHDR2.at_bill_account_balance
    FROM PVIEW.PAYMENT_ADJUSTMENT PYMTADJ
    LEFT OUTER JOIN PVIEW.BILL_HDR BILLHDR
    ON PYMTADJ.ky_enroll = BILLHDR.ky_enroll
    AND BILLHDR.dt_bill <= '15-Jun-2009'
    INNER JOIN PVIEW.BILL_HDR BILLHDR2
    ON BILLHDR.ky_enroll = BILLHDR2.ky_enroll
    AND MAX(BILLHDR.dt_bill) = BILLHDR2.dt_bill
    Any help would be GREATLY appreciated.
    Thanks.
    PSULionRP

    [email protected] wrote:
    But now the next riddle is this. I have another table I have to query against using those MAX Dates. Is there any way to use those MAX Dates as my Join criteria for another table???Sure, it is called in-line view:
    SELECT whatever-you-need
      FROM (
    SELECT   pymtadj.ky_payment_adjustment, pymtadj.ky_enroll,
             pymtadj.dt_payment_adjustment, pymtadj.at_payment_adjustment,
             MAX (billhdr.dt_bill) last_bill_date,
             MAX (billhdr.dt_reading_from) "Last Bill Period From Date",
             MAX (billhdr.dt_reading_to) "Last Bill Period To Date",
             MAX (billhdr2.at_bill_account_balance)KEEP (DENSE_RANK FIRST ORDER BY billhdr.dt_bill DESC) some_alis
        FROM pview.payment_adjustment pymtadj LEFT OUTER JOIN pview.bill_hdr billhdr
             ON pymtadj.ky_enroll = billhdr.ky_enroll
           AND billhdr.dt_bill <= TO_DATE ('15-Jun-2009', 'DD-Mon-YYYY')
             LEFT OUTER JOIN pview.bill_hdr billhdr2
             ON billhdr.ky_enroll = billhdr2.ky_enroll
    GROUP BY pymtadj.ky_payment_adjustment,
             pymtadj.ky_enroll,
             pymtadj.dt_payment_adjustment,
             pymtadj.at_payment_adjustment
    ) inline_view JOIN another_table ON(inline_view."Last Bill Period From Date" = another_table.some_column1)SY.

  • Problems Using MAX

    Hi, I have a GPIB-USB-B cable. In order to configure it I need to use MAX. The problem is that whenever I open MAX, it restarts my computer whenever I click on anything in the program. Is this a problem with the MAX software or something screwy in my computer.
    thanks
    ap1150

    ap1150,
    It sounds like you have some corrupt configuration files. Try deleting your 'Data' directory in ../National Instruments/MAX. Then restart MAX and see if the behavior continues. As a side note you can prevent your machine from auto reboots by going to your System properties (in the control panel). Click on the 'Advanced' tab and uncheck the 'Automatically restart' box. Let me know if this helps!
    Craig H.
    NI Applications Engineering

  • Display structure vibration frequency using MAX

    I have to display the structure vibration frequency using MAX, how can I perform the impact test if I'm using an impact hammer and accelerometer?

    Jesus Miguel,
    To use Acquire N Scans Digital Trig.vi you should become familiar with the description of this VI. (I know it is hard to comprehend. I also find it hard to read.) It explains the function of the VI, how to connect the signals, and what the controls of the front panel do. There are step by step instructions for you to follow.
    I suggested this VI because it can do the following:
    It can start and stop acquisition based on an external signal (for example the same signal that starts and stops the hammer).
    It will acquire the signal from the sensor into a buffer and create an array of values that you can then analyse using other tools in LabVIEW.
    You must tell the VI how to acquire the data. You must know the frequency of vibrations that interest you.
    I would use an oscilloscope to examine the vibrating system first, although you could do this with LV using a continuous analog input VI (use search examples to find). or you could use an oscilloscope from the DAQ solutions.
    Suppose you see that your vibration is 1MHz. Then you must sample the signal according to Nyquist. If you want only to accurately gauge frequency then you must scan at a rate at least two times this frequency. If you wish to look closely at the shape of the 1MHz vibration you must sample at at least ten times the signal frequency. You need to know the duration of the vibration. Will you strike the structure once and sample the ringing as the system disipates energy? You need to decide how long to sample this data. The number of scans to acquire is the sample rate times the time of acquisition. Pretrigger scans allows you to sample data prior to the trigger.
    The output of this VI is a screen representation of the data (waveform graph), and a "bundle" containing the data and t0 and dt (the intial time of the graph and the increment of time between data). You can strip off (unbundle) the t0 and dt and use only the array that remains for analysis purposes. What exactly do you wish to do with the results of this acquisition? FFT?
    One of your main concerns will be signal conditioning. You must know the characteristics of the output from the accelerometer amplifier. In MAX you will prepare a channel to sense a signal of this type. Then you can enter the channel name in the channels control of the VI. You should review the requirements of you DAQ card so that you know the levels of input that can be allowed. You must not exceed the limits or you can damage the DAQ card. Unfortunately, I have never used SCXI so I will be of little help in that regard.
    Typically you want to condition your input from the sensor system so that it uses the entire range of input resolution. For example, if you have 24 bit resolution from 0V to 10V, you would not want your input to vary from 0V to 1V. You would only have 1/24bits of resolution in this range. Gain can be set using SCXI tand MAX to prepare the channel properly.
    Most importantly, you must start using the equipment and software. Once you have conditioned the signal so that the DAQ system is protected from damage, you should begin by trying out VI's to familiarize yourself with the system.
    Stay in contact and ill try to be helpful,
    Mike
    Jesus Miguel wrote>>
    I have to display the structure vibration frequency using MAX, how can I perform the impact test if I'm using an impact hammer and accelerometer
    I looked VI Adquire N Scans Digital Trig.vi but I didn't know how to
    use it. I connected the accelerometer output to one channel (CHANNEL 0)
    input of the amplifier (NEXUS by Br�el&Kjaer) and the amplifier output
    to the input (CHANNEL 0) of SCXI-1140. The hammer output is connected
    to the NEXUS input (CHANNEL 1) and the amplifier output to the input
    (CHANNEL 1) of SCXI-1140 (CHANNEL 1).
    I use LabVIEW 6.1 version, but LabVIEW is new for me and I can't use it properly yet. Is possible to use any DAQ solutions (or any modification) to display the structure vibration frequency to perform the impact test if I'm using an impact hammer and accelerometer?
    I connected the accelerometer output to one channel(CHANNEL 0) input of the amplifier (NEXUS by Br�el&Kjaer) and the amplifier output to the input (CHANNEL 0) of SCXI-1140. The hammer output is connected to the NEXUS input (CHANNEL 1) and the amplifier output to the input (CHANNEL 1) of SCXI-1140 (CHANNEL 1).
    end quote>>

  • Using MAX in transformations / Start Routine

    Hi,
    I am trying to use MAX function in an ABAP routine (transformation / Start) and it shows following error -
    "Unknown column name "MAX(/BIC/ZQMCOUNT)" until runtime, you cannot specify a field list.". Here is part of my code -
    >>
    data: v_counter(10) type n.
    SELECT MAX(/BIC/ZQMCOUNT)
    INTO v_counter
    FROM /BIC/AZDPM_DS300.
    <<
    Any thoughts please.
    Regards
    Vikash

    Hi there,
    Sometimes you have to put some spaces between the parantehsis in the max, min or count, like this:
    data: v_counter(10) type n.
    SELECT MAX( /BIC/ZQMCOUNT )
    INTO v_counter
    FROM /BIC/AZDPM_DS300.
    Can you try that?
    Diogo.

Maybe you are looking for