Solved

10774:  unique combination for c1 and c2

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

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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

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…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

630 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