Solved

10774:  unique combination for c1 and c2

Posted on 2014-10-10
3
111 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
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 48

Assisted Solution

by:PortletPaul
PortletPaul earned 500 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

911 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

16 Experts available now in Live!

Get 1:1 Help Now