Solved

MAX function

Posted on 2014-12-15
7
86 Views
Last Modified: 2014-12-16
suppose the records in a table containing the records below :

inventbatchid       itemid     a2      a3       a4      PIC3            
PO10901                 AB0001    A       DX      20       c:\photo\abc135.jpg
PO10901                 AB0001    A       DX      20       c:\photo\abc13512321321.jpg
PO10901                 AB0001    A       DX      20       c:\photo\ac135.jpg

In this case, which record will be returned by "MAX" function ? Tks

select inventbatchid,itemid,a2,a3,a4,
 Tent,
 max(case typeid when 'ImgS' then pic else '' end) as 'PIC3',
 max(case typeid when 'sketchA' then pic else '' end) as 'PIC2',
 max(case typeid when 'sketchB' then pic else '' end) as 'PIC1'  
into #tmp3 from #tmp2
0
Comment
Question by:AXISHK
  • 3
  • 3
7 Comments
 
LVL 48

Expert Comment

by:PortletPaul
ID: 40501934
without typeid in the data we cannot answer

ie. the case expressions require a value in the field typeid, that value is not provided in your data
0
 

Author Comment

by:AXISHK
ID: 40501974
TypeID will be either 'IMgS', 'sketchA' and 'sketchB'. In the example above, typeID is 'ImgS'.
0
 
LVL 48

Expert Comment

by:PortletPaul
ID: 40501978
which record will be returned by "MAX" function ?
c:\photo\ac135.jpg
0
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 

Author Comment

by:AXISHK
ID: 40501992
What's the selection criteria ?
0
 
LVL 48

Accepted Solution

by:
PortletPaul earned 300 total points
ID: 40502399
The same as text sorting. The c after a is the "biggest" in that location of the 3 strings, so that makes this the maximum
0
 
LVL 69

Assisted Solution

by:Scott Pletcher
Scott Pletcher earned 200 total points
ID: 40503025
Presumably you'd want each max based on a specific inventbatchid, something like this:


select t2.inventbatchid,t2.itemid,t2.a2,t2.a3,t2.a4,t2.Tent,
    t2_pics.PIC3,t2_pics.PIC2,t2_pics.PIC1
into #tmp3
from #tmp2 t2
inner join (
    select inventbatchid,
        max(case typeid when 'ImgS' then pic else '' end) as 'PIC3',
        max(case typeid when 'sketchA' then pic else '' end) as 'PIC2',
        max(case typeid when 'sketchB' then pic else '' end) as 'PIC1'
    from #tmp2
    group by inventbatchid
) AS t2_pics on
    t2_pics.inventbatchid = t2.inventbatchid
0
 

Author Closing Comment

by:AXISHK
ID: 40503939
Tks
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question