Solved

10774:  unique combination for c1 and c2

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

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.
In this article I will describe the Copy Database Wizard 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.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

809 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