Counting Distinct Records Of Column 1 With A Certain Value In Column 2

Feb 6, 2008

Ok, so I need to count the Distinct records from column 1 in which there is not a true value in any of the records for that distinct column 1 number. Here is a short example of my records:
dbo_dbWafer_Slicing


dbo_dbWafer_Slicing



WaferID
SawDate
SawRunNumber
   Pass





03-157.05    

1/8/2008 9:54:00 AM    
03-157
0




03-157.03
1/8/2008 9:53:00 AM    
03-157
-1




03-157.04
1/8/2008 9:53:00 AM    
03-157
0




03-157.02
1/8/2008 9:52:00 AM    
03-157
-1




03-157.01
1/8/2008 9:50:00 AM    
03-157
-1




03-165.06
1/4/2008 10:46:00 AM    

03-165
0




03-165.07
1/4/2008 10:46:00 AM    
03-165
0




03-165.04
1/4/2008 10:45:00 AM    
03-165
0




03-165.05
1/4/2008 10:45:00 AM    
03-165
0




03-165.02
1/4/2008 10:44:00 AM    
03-165
0




03-165.03
1/4/2008 10:44:00 AM    
03-165
0




03-165.01
1/4/2008 10:43:00 AM    
03-165
0







 So, how many Distinct SawRunNumbers had no passing wafers? In trying to do this I've come up with:
"SELECT COUNT(DISTINCT SawRunNumber) AS BouleCount FROM dbWafer_Slicing WHERE (SawDate >= @MinDate) AND (SawDate <= @MaxDate) AND (Pass = 1) HAVING (COUNT(DISTINCT WaferID) > 0)"
but that doenst work. It still counts records where pass = 0 for distinct SawRunNumbers even if one record within that SawRunNumber is passing. From the above sample data I should get a result of 1 not 2 or 3. Can I do this with this set of data? I'm using SQL Server 2005 EE.
Thanks for your help.
 

View 6 Replies


ADVERTISEMENT

Counting Multiple Values From The Same Column And Grouping By A Another Column

Sep 16, 2004

This is a report I'm trying to build in SQL Reporting Services. I can do it in a hacky way adding two data sets and showing two tables, but I'm sure there is a better way.

TheTable
Order# Customer Status

STATUS has valid values of PROCESSED and INPROGRESS

The query I'm trying to build is Count of Processed and INProgress orders for a given Customer.

I can get them one at a time with something like this in two different datasets and showing two tables, but how do I achieve the same in one query?

Select Customer, Count (*) As Status1
FROM TheTable
Where (Status = N'Shipped')
Group By Customer

View 2 Replies View Related

How To Show Distinct Rows Of The Column Of The Dataset And Number Of Distinct Rows Of That Column

Mar 29, 2007

suppose i have aDataset with 11 rows. field1 with 5 rows of aaa, 6 rows of "bbb"

I want's some thing like

field1 rowcount
aaa 5
bbb 6

View 1 Replies View Related

Transact SQL :: Distinct By One Column By Selecting Multiple Column?

Jul 17, 2015

I have a SQL Query issue you can find in SQL Fiddle

SQL FIDDLE for Demo

My query was like this

For Insert
Insert into Employee values('aa', 'T', 'qqq')
Insert into Employee values('aa' , 'F' , 'qqq')
Insert into Employee values('bb', 'F' , 'eee')
Insert into Employee values('cc' , 'T' , 'rrr')
Insert into Employee values('cc' , 'pp' , 'aaa')
Insert into Employee values('cc' , 'Zz' , 'bab')
Insert into Employee values('cc' , 'ZZ' , 'bac')
For select
select col1,MAX(col2) as Col2,Max(Col3) as Col3
from Employee
group by Col1

I supposed to get last row as 

    cc  Zz  bab

Instead I am getting 

  cc  Zz  rrr 

which is wrong

View 8 Replies View Related

Reporting Services :: Count Values In A Column Based Upon Distinct Values In Another Column In SharePoint List

Sep 7, 2015

We have SharePoint list which has, say, two columns. Column A and Column B.

Column A can have three values - red, blue & green.

Column B can have four values - pen, marker, pencil & highlighter.

A typical view of list can be:

Column A - Column B
red  - pen
red - pencil
red - highlighter
blue - marker
blue - pencil
green - pen
green - highlighter
red  - pen
blue - pencil
blue - highlighter
blue - pencil

We are looking to create a report from SharePoint List using SSRS which has following view:

                    red     blue   green
    pen            2       0      1
    marker       0       1      0
    pencil          1       3      0
    highlighter  1       1      1 

We tried Sum but not able to display in single row.

View 2 Replies View Related

Exclude Records From A Table Where ID Column Is Same But Mail Code Column Is Multi-valued

Nov 12, 2012

I am trying to exclude records from a table where the ID column is the same but the Mail code Column is multi-valued.For Example: (the table looks like....)

ID Mail_code
111111 XNT
111111 N11
111111 XNC
222222 XNC
222222 XNL
333333 XNC

So, if there is any ID that has a value of XNC, I want to exclude the ID all together from my output regardless of the other values.

View 3 Replies View Related

Counting Projects In A Column

Mar 30, 2001

I have a column called line_number and a column called projectid's.

I need to count count the projectid's as they occur in the line_number
column.

This is how I need the columns to look.

projectid line_number
111 1
111 2
111 3
222 1
222 2

I have written a cursor to get all the data into the table. But not sure how to get this column to count distinct projectid's.

I really appreciate any help.

Thanks again,
Dianne

View 2 Replies View Related

Counting No Of Words In A Column

Sep 13, 2006

Hi,


for some reason, i had to write a function to count the number of words in a particular column in a table. (pl find the attachment). i would like to know whether there is any other mechanism with which we can count the number of words in a particular column.

for example, if the column data is,'This Is A Test', the function, will return 4.
pl suggest any other efficient strategies to accomplish this


thanks

View 11 Replies View Related

Counting Popular Value In A Column

Aug 31, 2006

I have a table with a column that has 200 000 000 value where 18 000 000 are distinct. I want to know which value are found more than 50 000 times in the column

How would you do it without killing the database with a query that will take too much resource?

View 2 Replies View Related

Distinct Sum For My Column

Jul 30, 2007

Hi,
Bonjour,

I want distinct sum for one of my column.But iam not able to do that.

I tried DISTINCTSUM function given inMSDN, but it always return ZERO.

My function call in FOOTER section is called first, before my DETAILS section function call.


please help me for this.

thanks and regards
Hemant

View 9 Replies View Related

Get Distinct On Only One Column

Aug 12, 2015

I am using this below query to generate this below result set. I want to display only one record as blank, it should not be duplicate records.

SELECT [MDMTerminalID], ISNULL([TerminalAlias], 'BLANK') , [RegionID] FROM [dbo].[Terminal]
Union
select -1,'All', (select top 1 areaid from area where name = 'Other')

View 2 Replies View Related

One Column DISTINCT On 2 Tables

Oct 19, 2006

hello I am trying to get a distinct on one column and 2 tables but it doesnt work

Table1
ID_Table1
Name1
Number1

Table2
ID_Table2
ID_Table1
Name2


I want to get : ID_Table1, DISTINCT(Name1), Name2
WHERE Name1 LIKE 'A%'

how can I do it ?

thank you

View 4 Replies View Related

How To Select Distinct On One Column

Apr 15, 2015

I have this

SELECT DISTINCT inta, name, PHN#, fROM nydta.adres
WHERE inta <> ' '

I want the distinct for inta because alot of the time phone is blank so those are coming thru i do want all columns, but distinct for inta.

View 1 Replies View Related

Getting Distinct Values On One Column ?

Sep 11, 2007

We have a query in which there are 20,000 rows and 90 distinct ID's

If we say

SELECT distinct siteid ,ts1, ts2, ts3, ts4, ts5, ts6, ts7, ts8

from #TEMPX

we get the 90 distinct values, but if we say


SELECT distinct siteid ,ts1, ts2, ts3, ts4, ts5, ts6, ts7, ts8, ts1avg, ts2avg, ts3avg, ts4avg, ts5avg, ts6avg, ts7avg, ts8avg from #TEMPX

TS1 contains 90 distinct values, whily ts1avg has 2,000 disitinct rows

Is there a way to get Distinct to work against only one column, i.e. SiteID ?

View 2 Replies View Related

Distinct On Single Column?

Aug 30, 2007

Hi,

This is a query that joins a vouple of tables to display all the products purchased by a group of customers and the price they paid for it.


SELECT DISTINCT (p.code),p.descript_1 + ' ' + p.descript_2 + ' ' + p.descript_3 as description,sol.p_sales as price,sol.q_ordered as quantity,(sol.p_sales * sol.q_ordered) as total,so.date_in as dateFROM EfasLive..debtor AS d

INNER JOIN Informatica..so AS so ON so.deb_code = d.code AND so.co_code = d.co_code

INNER JOIN Informatica..so_line AS sol ON sol.code = so.code AND sol.co_code = so.co_code AND sol.acc_year = so.acc_year AND sol.efas = so.efas

INNER JOIN EfasLive..part AS p ON p.code = sol.part

WHERE d.[grp{003}] = 'GROUP' AND p.co_code = 1 AND p.code NOT LIKE '&%' AND so.date_in > DATEADD(m,-3,GETDATE()) AND sol.q_ordered > 0

ORDER BY (p.code), datum DESC

The problem with this is that it returns multiple lines for every product (p.code). Like so:


code description price quantity total date
603244 description_1 17.950000 150.000000 2692.500000000000 2007-08-01 00:00:00

603244 description_1 17.950000 150.000000 2692.500000000000 2007-07-10 00:00:00

603245 description_2 17.950000 40.000000 718.000000000000 2007-07-24 00:00:00

603245 description_2 17.950000 25.000000 448.750000000000 2007-07-16 00:00:00

603663 description_3 16.890000 27.000000 456.030000000000 2007-07-20 00:00:00

603663 description_3 16.890000 150.000000 2533.500000000000 2007-07-10 00:00:00

603663 description_3 16.890000 30.000000 506.700000000000 2007-07-03 00:00:00

I'd like there to be only 1 line for every different code with it's description. The idea is that the other rows are dropped and that only the first one remains. The one with the most recent purchase. I tried with GROUP BY but that's probably wrong since you'd have to add all the other columns as well and you end up with the same one. And even with adding a HAVING at the end I can't see how this could be solved


edit: There aren't any actual relationships in the tables (it's ancient you see ...) I'm using SQL 2005 though.

View 3 Replies View Related

SELECT DISTINCT On One Column

Oct 19, 2006

I know this is a popular problem, but i haven't found an answer to my situation.
I have a table (myTable) with three Columns (Column1, Column2, Column3). Column1 entries are unique (with unique identifier), Column2 entries are not unique.
I want to do a SELECT DISTINCT on myTable so that Column2 is unique and i get all the other columns. I thought something like this would work

SELECT DISTINCT Column2 as Col2, newid() as Col1, Column3 as Col4
-- I am getting uniqueidentifier for each row as well

This doesn't seem to work however. I still get all the rows because Col1 is unique.
since i am using aliases, the usual syntax doesn't work either.

any help would be greatly appreciated!

View 2 Replies View Related

T-SQL (SS2K8) :: Max With Distinct Two Columns And Corresponding Third Column

Apr 30, 2014

T1
-------
a1
a2
datetime
a4
a5
.....

i need distinct max between a1&a2 which i can get no problem but i cant get that unique datetime that correspond to a1&a2 in 1 query because this is will a subquery in a big query. Creating another temp table etc is not an option for me. for every specific a1 there is many entries of a2 + timedate etc.

create table abc_test (
id int
,runs int
,date1 datetime

[code]....

I can either get distinct ID + latest date or ID + largest #ofRuns, both will do but also need the third column.

View 5 Replies View Related

T-SQL (SS2K8) :: Distinct On Varchar Column

May 21, 2015

The below TSQL query takes about 19 minutes to run

SELECT count(distinct SessionID) ) FROM SessionTracker

Sessionid is a varchar(138)

Through SQL profiler - I notice implicit conversion taking place when running distinct option.

Select count(sessionid) from sessiontracker

- runs in milliseconds.

View 1 Replies View Related

To Return Distinct Column Using INNER JOIN

Apr 23, 2008

Hello all,

I am using INNER JOIN to connect 2 tables together but I wish it to return distinct columns instead of repeating itself !

eg.
Current output would be:
UserID Name UserID OrderID
1 John 1 5
2 Bob 2 6

I want it to be:
UserID Name OrderID
1 John 5
2 Bob 6


I need to use SELECT * as there are many many columns and wish to save time :)


Cheers,

James

View 3 Replies View Related

Select With Multiple Column And Distinct

Jun 22, 2008

Hi guys, I'm hoping there's someone out there with more sql knowledge and experience than me. I'll try to explain everything.

I'm trying to create a select statement but i'm not gettting the required results mainly because i think its a very complicated select.

Here is the scenario.

The table has 12 columns

ProductID Colour MD01 MD02 MD03 MD04 MD05 MD06 MD07 MD08 MD09 MD010


The ProductID is naturally the unique key.

There is always a colour value. But there is not always a value in the MD columns. For example one Product may have values in MD01 MD02 MD03 MD04 MD05 whilst another has values in all MD columns.

My problem is thatI am trying to create a results list based upon selecting distinct values from the colour and md columns

In otherwords i can't have more than only one instance of a word appearing in the recordset list

I'm really struggling with this because there are only 6 colours so if i set distinct purely on 6 colours i only get back 6 rows.

When I try to set disctinct across all the MD columns it seems to ignore it and lists results for example in the table

ProductID Colour MD01 MD02 MD03 MD04 MD05 MD06 MD07 MD08 MD09 MD010
1 red car bike
2 blue bike car train

my select lists results as
red
car
bike
blue
bike
car
train

and it is as if it only carries out the distinct command across the row not across all columns for all rows if you see what i mean?

I need to be able to list all data from all rows that have values in the MD columns and colour column but not list the values more than once and not list "empty" (NULL) columns. Does this make sense?

This is the select statement i wrote.

Select DISTINCT md00, md01, md02, md03, md04, md05, md06, md07, md08, md09, md10, colour FROM TEMPLATES WHERE md00 IS NOT NULL or md01 IS NOT NULL or md02 IS NOT NULL or md03 IS NOT NULL or md04 IS NOT NULL or md05 IS NOT NULL or md06 IS NOT NULL or md07 IS NOT NULL or md08 IS NOT NULL or md09 IS NOT NULL or md10 IS NOT NULL

But it returns empty columns and it returns every instance of the same word so in other words the distinct command doesn't seem to be working at all?

I don't know if this is because of my asp code I am trying to list results with the rescordset?

<%
While ((Repeat1__numRows <> 0) AND (NOT template_rs.EOF))
%>

<%=(template_rs.Fields.Item("md01").Value)%>
<%=(template_rs.Fields.Item("md02").Value)%>
<%=(template_rs.Fields.Item("md03").Value)%>
<%=(template_rs.Fields.Item("md04").Value)%>
<%=(template_rs.Fields.Item("md05").Value)%>
<%=(template_rs.Fields.Item("md06").Value)%>
<%=(template_rs.Fields.Item("md07").Value)%>
<%=(template_rs.Fields.Item("md08").Value)%>
<%=(template_rs.Fields.Item("md09").Value)%>
<%=(template_rs.Fields.Item("md10").Value)%>
<%=(template_rs.Fields.Item("colour").Value)%>

<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
template_rs.MoveNext()
Wend
%>


I have one more problem. How can I also in addition to being able to list all distinct results list only results for a specific letter

for example

Select DISTINCT md00, md01, md02, md03, md04, md05, md06, md07, md08, md09, md10, colour FROM TEMPLATES WHERE md00 IS NOT NULL or md01 IS NOT NULL or md02 IS NOT NULL or md03 IS NOT NULL or md04 IS NOT NULL or md05 IS NOT NULL or md06 IS NOT NULL or md07 IS NOT NULL or md08 IS NOT NULL or md09 IS NOT NULL or md10 IS NOT NULL WHERE FIRST LETTER ='A'?


I am so far out of my depth here guys I am hoping that someone who has real knowledge of SQL can help me with this statement. I've been pulling my hair out for days now and getting just more and more frustrated listing the same results :(

-BB

View 20 Replies View Related

COUNT (Distinct Column) = 0 With GROUP BY

Mar 20, 2008

I have a table of users and date when they logged on to a system. I am trying to count how many distinct users logged on for each day of the week. The SQL below works when there's at least a user for each day. But when there is no user for a particular day such as Sunday, I still want it to return "SUN



0 "

I learned that you can use GROUP BY ALL and it works but the "ALL" is deprecated beyond SQL 2005.

------------------------------------
SELECT UPPER(LEFT(DATENAME(dw, StartTime), 3)) AS DayOfWeek,
COUNT(DISTINCT UserID) AS NumberOfUser

FROM testUserLoginDuration
WHERE Archived = 0
GROUP BY UPPER(LEFT(DATENAME(dw, StartTime), 3))
ORDER BY
CASE WHEN UPPER(LEFT(DATENAME(dw, StartTime), 3)) = 'MON' THEN 1
WHEN UPPER(LEFT(DATENAME(dw, StartTime), 3)) = 'TUE' THEN 2
WHEN UPPER(LEFT(DATENAME(dw, StartTime), 3)) = 'WED' THEN 3
WHEN UPPER(LEFT(DATENAME(dw, StartTime), 3)) = 'THU' THEN 4
WHEN UPPER(LEFT(DATENAME(dw, StartTime), 3)) = 'FRI' THEN 5
WHEN UPPER(LEFT(DATENAME(dw, StartTime), 3)) = 'SAT' THEN 6
WHEN UPPER(LEFT(DATENAME(dw, StartTime), 3)) = 'SUN' THEN 7
END

--------------
returns

MON 6
TUE 3
WED 5
THU 3
FRI 2
SAT 1

View 4 Replies View Related

SQL Counting Number Of Non-distinct Rows?

May 3, 2006

Hi, I have a table that for ease has this data in:R1, R2, R....z---------------------A | 12A | 22A | 30B | 0B | -1B | -3C | 100I want to generate a table for each distinct row in R1, gives a countof all the rows with data correspondingFor the above table I would getA | 3B | 3C | 1Im probably being stupid but cannot see this at the moment... pleasehelp.Thanks

View 3 Replies View Related

Need To Query A Database With Distinct Column And Row Counts

May 18, 2007

On my company site, I have created a database that is for the purpose of tracking google adwords, as well as pages that the user visits.  For instance, if you were to search for "guitars" and then click our ad, an entry is created in the database like thisKeyword:         SessionGUID:         PageVisited:                                                                          VisitedDateTime:Guitars            lkjfeilfjskdlfjsije         ~ViewCategory.aspx?Cat=Guitars,KW=Guitars                       12/01/2000 12:00amGuitars            lkjfeilfjskdlfjsije         ~ViewProduct.aspx?ProductID=1253&SubProductID=3            12/01/2000 12:03amGuitars            lkjfeilfjskdlfjsije        ~Search.aspx?Q=BC%20%Rich                                             12/01/2000 12:05am Pretty much, in our administrative area, I want to be able to have a table that would generate these results: Keyword              Total HitsGuitars                3So im guessing that obviously I would need to do a select distinct for the Keyword column, but how do I also have a column showing a count of the records? 

View 1 Replies View Related

Problem Creating View With DISTINCT Column

Oct 5, 2005

Hi Guys

I'm trying to create a view in SQL Server to display only one copy of all records in a table, where some of the records are exact matches to other records (except for an ID autoincrement field)

I have the following code that displays distinct titles:

sql Code:






Original
- sql Code




SELECT DISTINCT DocTitle
FROM dbo.TBL_TABLE_NAME






SELECT DISTINCT DocTitleFROM         dbo.TBL_TABLE_NAME



But when i use this code (adding one field to query), it displays all the duplicate records also, which I do not want:

sql Code:






Original
- sql Code




SELECT DISTINCT DocTitle, ID
FROM dbo.TBL_TABLE_NAME






SELECT DISTINCT DocTitle, IDFROM         dbo.TBL_TABLE_NAME




I want to get the distinct results for DocTitle, with 5 other columns added to the query so they can be displayed in a web page list.
The query I want is something like this, but I can not get it to work:

sql Code:






Original
- sql Code




SELECT DISTINCT DocTitle, ID, FirstName, LastName, Company, DocDescription, DocFile
FROM dbo.TBL_TABLE_NAME
ORDER BY DocTitle






SELECT DISTINCT DocTitle, ID, FirstName, LastName, Company, DocDescription, DocFileFROM         dbo.TBL_TABLE_NAMEORDER BY DocTitle



I know this query works from an MS Access DB, but I need it to work from SQL Server.

I am using SQL Server 2000

Any help is greatly appreciated.

Alex

View 1 Replies View Related

Distinct Record Equal To 2 Values From Same Column

Dec 6, 2013

Distinct name that match both subjects (math, science) from classname in level 2 only. Not sure where to even start. Example table below:

name subject level
bob math 2
hank math 1
joe science 2
bob science 2
joe math 2
ben science 2
carl science 1

View 2 Replies View Related

Select Distinct Column While Joining Tables

Oct 29, 2014

I am attempting to run the following select statement joining multiple tables but in the end result I would like only Distinct/Unique values to be returned in the invlod.lodnum column.

[select pw.schbat, adrmst.adrnam, adrmst.adrln1, adrmst.adrcty, adrmst.adrstc, adrmst.adrpsz,
invlod.lodnum,
shipment.host_ext_id, shipment_line.ordnum, car_move.car_move_id
from aremst join locmst
on (aremst.arecod = locmst.arecod)
and (aremst.wh_id = locmst.wh_id)

[Code] .....

View 4 Replies View Related

Select Distinct Record Only If Certain Column Not Null

Apr 5, 2007

Been trying to come up with a query to filter-down my sample set intodistinct records. For instance, lets say column1 is a sample set,column2 is the parameter, and column3 is a name and column4 is a type(lets also say there is a fifth column (id) that is an id). What Ineed is one record per type per sample only if type is given, if not,then return that record as well.I've used a subquery to get as close to the desired query is aspossible:select * from table1where id in (select min(id) from table1where column1="A"group by column1, column2)Here's an example of all data for sample "A":1 2 3 4----------A 1 X PA 1 Y PA 1 Z PA 2 WA 3 WA 4 T PA 5 U PA 6 V PA 7 TA 7 UA 7 VI want output :1 2 3-------A 1 X PA 2 WA 3 WA 4 T PA 5 U PA 6 V PA 7 TA 7 UA 7 VExcept the above query will exclude the last two records becausecolumn3 is not 'grouped by'.Basically I need to reduce any 'range' of records per sample (columna) where column4 is not null (ie = 'P'), to only one record andkeeping all others. Thanks in advance:-B

View 6 Replies View Related

SELECT DISTINCT And ORDER BY With Aliased Column

Feb 14, 2008



This query demonstrates a problem I have run across:


USE AdventureWorks

GO

-- This query works fine.

SELECT DISTINCT FirstName AS Name1 FROM Person.Contact ORDER BY FirstName

GO

-- This query also works fine.

SELECT ISNULL(FirstName, '') AS Name1 FROM Person.Contact ORDER BY FirstName

GO

-- This query returns error 145

SELECT DISTINCT ISNULL(FirstName, '') AS Name1 FROM Person.Contact ORDER BY FirstName

GO


The last query returns the error "ORDER BY items must appear in the select list if SELECT DISTINCT is specified".
It will work if I change ORDER BY to use "Name1" instead of "FirstName", but in the situation I have at hand, the query is generated by third-party software and I don't have the ability to change it.
Can anyone explain why what's going on here? Oddly, this same query will work if I run it against SQL Server 2000.

View 8 Replies View Related

Counting Query (SQL DataSource) By Selecting Distinct

May 21, 2008

I am trying to write a SQL DataSource Statement that will do the following:
Select the Distinct Dates, count up the number of rows with that date
So for example:
Date                Number with that Date
12/12/2007        3
14/12/2007        2
Database:
12/12/2007         Content 1
14/12/2007         Content 2
12/12/2007         Content 3
14/12/2007         Content 4
12/12/2007         Content 5

View 6 Replies View Related

DISTINCT Not Working To Eliminate Duplicate Column Names

Feb 28, 2008

In my employee table has the following fields empid, empFname, empLname, email, city
Say it has data like follows:
1, Lucy, Sam, l@some.com, city1
2. Sam, Wite, l@some.com, city2
3. Laura, Mac, l@some.com, city2
4. Stacy, Soo, s@no.com , city1
So in my case I want to show all the column but I want to eliminate multiple email addresses.  I tried Distinct but its not workin because here every column is not distinct.  So what should I use?
In my case I only want to show empID 1, 3, 4.  I want to show all the columns

View 5 Replies View Related

Select Distinct Column Data With Other Values From The Table

Dec 16, 2004

I have a table 'wRelated' with the following columns

[related_id] [int]
[channel_id] [int]
[mui] [varchar]
[price_group_id]
[type_id] [int]
[related_mui] [varchar] (100)
[date_started] [smalldatetime]
[date_ended] [smalldatetime]
[date_entered] [datetime]
[deleted] [tinyint],
[rank] [int]
data in column [mui] is repeated as the table has more than one entries for the same [mui],
The requirement is to select the distinct[mui] but value in all the other columns for the same mui should be select in the next row with null for the same [mui]
The recordset expected should be something like this.

[mui],[related_mui],[price_group_id],[date_entered],[date_ended] m123,rm345,'pr','12-10-2003',12-12-2004'
null,rm789,'ar','12-1-2003',26-2-2004'
null,rm999,'xy','14-12-2002',12-2-2004'
m777,rm889,'pr','12-12-2004',12-12-2004'
null,rm785,'yy','1-10-2002',12-12-2004'
m888,rm345,'pr','2-8-2003',12-12-2004'
null,rm345,'tt','30-7-2002',12-12-2004'

I have tried Unions and temporary table inserts.

View 1 Replies View Related

T-SQL (SS2K8) :: How To Select Rows Based On One Distinct Column

Apr 18, 2014

--------------------------------------------------
SalesOrder-ItemName-Price-Category
-------------------------------------------------
01-Camera-100-Electronic
01-Memory-4GB-10-Memory
01-Battery-5-Battery
02-Keyboad-10-Accessories
02-Mouse-5-Accessories
03-CPU-300-Hardware
03-Motherboad-400-Hardware

From above rows i would like to select rows based on one distinct column SalesOrder, i want output like below.

-----------------------------------
SalesOrder-ItemName-Price-Category
-----------------------------------
01-Camera-100-Electronic
02-Keyboad-10-Accessories
03-CPU-300-Hardware

CREATE TABLE Table1 (SalesOrder varchar(10), ItemName VARCHAR(100), Price INT, Category VARCHAR(100))

[Code] ......

View 2 Replies View Related

SELECT INTO A New Table All Columns Based On DISTINCT Value Of One Column

Oct 31, 2014

‘Trying to SELECT INTO a new table all columns of a table based on a DISTINCT value of one column so for example:

SELECT *
INTO new_table
FROM old_name
WHERE old_table.column IS DISTINCT’

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved