Solved

MAX function

Posted on 2014-12-15
7
83 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

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:ScottPletcher
ScottPletcher 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

     When we have to pass multiple rows of data to SQL Server, the developers either have to send one row at a time or come up with other workarounds to meet requirements like using XML to pass data, which is complex and tedious to use. There is a …
SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now