Solved

10774:  unique combination for c1 and c2

Posted on 2014-10-10
3
109 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
  • 2
3 Comments
 
LVL 48

Accepted Solution

by:
PortletPaul earned 500 total points
Comment Utility
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
Comment Utility
you can tell the NEW_COLUMN begins with the value of 50

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

Assisted Solution

by:PortletPaul
PortletPaul earned 500 total points
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
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…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

772 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

10 Experts available now in Live!

Get 1:1 Help Now