Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

10774:  unique combination for c1 and c2

Posted on 2014-10-10
3
Medium Priority
?
119 Views
Last Modified: 2014-10-10
Hello experts:

for each unique combination of materialreal codigocliente and I must add a column with the same number

  SELECT
         [organizacionVenta]
      ,[codigoCliente]
      ,[1-SPOT 2-NSPOT]
      ,[codigoCentro]
      ,[1-Exp 2-Fil 3-Int 4-Loc]
      ,[materialReal]
        ,1 IdAnioEjercicio
  FROM [BPS_STAGE].[dbo].[Copia de Base PG]
  order by  codigoCliente,materialReal  desc

organizacionVenta	codigoCliente	1-SPOT 2-NSPOT	codigoCentro	1-Exp 2-Fil 3-Int 4-Loc	materialReal	IdAnioEjercicio
PE10	100001	2	1000	4	005000090000080324	1
PE10	100001	2	1000	4	005000090000080324	1
PE10	100001	2	1000	4	005000090000080324	1
PE10	100001	2	1000	4	005000090000080324	1
PE10	100001	2	1000	4	005000090000080324	1
PE10	100001	2	1000	4	005000090000080324	1
PE10	100001	2	1000	4	005000090000080324	1
PE10	100001	2	1000	4	005000090000080324	1
PE10	100001	2	1000	4	005000090000080324	1
PE10	100001	2	1000	4	005000090000080324	1
PE10	100001	2	1000	4	005000090000080324	1
PE10	100001	2	1000	4	005000090000080324	1
PE10	100001	2	1000	4	005000090000080305	1
PE10	100001	2	1000	4	005000090000080305	1
PE10	100001	2	1000	4	005000090000080305	1
PE10	100001	2	1000	4	005000090000080305	1
PE10	100001	2	1000	4	005000090000080305	1
PE10	100001	2	1000	4	005000090000080305	1
PE10	100001	2	1000	4	005000090000080305	1
PE10	100001	2	1000	4	005000090000080305	1
PE10	100001	2	1000	4	005000090000080305	1
PE10	100001	2	1000	4	005000090000080305	1
PE10	100001	2	1000	4	005000090000080305	1
PE10	100001	2	1000	4	005000090000080305	1
PE10	100001	2	1000	4	005000090000080288	1
PE10	100001	2	1000	4	005000090000080288	1
PE10	100001	2	1000	4	005000090000080288	1
PE10	100001	2	1000	4	005000090000080288	1
PE10	100001	2	1000	4	005000090000080288	1
PE10	100001	2	1000	4	005000090000080288	1
PE10	100001	2	1000	4	005000090000080288	1
PE10	100001	2	1000	4	005000090000080288	1
PE10	100001	2	1000	4	005000090000080288	1
PE10	100001	2	1000	4	005000090000080288	1
PE10	100001	2	1000	4	005000090000080288	1
PE10	100001	2	1000	4	005000090000080288	1

Open in new window

0
Comment
Question by:enrique_aeo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 49

Accepted Solution

by:
PortletPaul earned 2000 total points
ID: 40374099
Try this:

select
      *
      , dense_rank() over(order by codigoCliente, materialReal) as NEW_COLUMN
from [Copia de Base PG]

Open in new window


Why are you using 10774 in the question titles?

-----
for reuse if needed: http://sqlfiddle.com/#!3/16c64/2
0
 

Author Comment

by:enrique_aeo
ID: 40374105
you can tell the NEW_COLUMN begins with the value of 50

Course 10774A: Querying Microsoft SQL Server 2012
0
 
LVL 49

Assisted Solution

by:PortletPaul
PortletPaul earned 2000 total points
ID: 40374179
I don't understand what this means:

"you can tell the NEW_COLUMN begins with the value of 50"

??? this ???

50 + dense_rank() over(order by codigoCliente, materialReal) as NEW_COLUMN
0

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

670 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