Home Page
Articoli
Tips & Tricks
News
Forum
Archivio Forum
Blogs
Sondaggi
Rss
Video
Utenti
Chi Siamo
Contattaci
Username:
Password:
Login
Registrati ora!
Recupera Password
Home Page
Stanze Forum
SQL Server 2000/2005/2008, Express, Access, MySQL, Oracle
Assegnazione codici
lunedì 01 luglio 2013 - 16.19
Elenco Threads
Stanze Forum
Aggiungi ai Preferiti
Cerca nel forum
Elenco Tags
Access (.mdb)
sergranero
Profilo
| Junior Member
100
messaggi | Data Invio:
lun 1 lug 2013 - 16:19
Cioa, mi hanno passato questo database per assegnare lo stesso numero a dei dati duplicati (tramite la query QueryNominativiUniciConProgressivo) ( trovate il database in allegato )
Ora mi servirebbe ( se è possibile farlo ) che al posto del numero progressivo Nr venisse inserito il nome della Marca, il numero "Nr" e _01..._02 etc etc quando il "Nr" che sta ad indicare che il Nr è più volte ripetuto come nel caso dell'ID 0003-0004 oppure 0042-0044-0045-0046
Anche nel caso del 0037 dovrebbe comparire il _01
In pratica ciò che vorrei è ottenere questo
ID 0037 --> Aiwa0001_01
ID 0003 --> Austin0002_01
ID 0004 --> Austin0002_02
ID 0018 --> Sony0004_01
ID 0020 --> Sony0004_02
Grazie
Ho trovato questo codice su internet.. ve lo riporto in modo che può essere utile ad altri
Dim db As Database
Dim rstBrand As Recordset
Dim rstModel As Recordset
Dim rstVersion As Recordset
Dim sSQL As String
Dim sBrand As String
Dim sModel As String
Dim sVersion As String
Dim sUK As String
Dim iMax As Integer
Dim iVersion As Integer
Set db = CurrentDb
sSQL = "SELECT Brand FROM tblTest GROUP BY Brand ORDER BY Brand"
Set rstBrand = db.OpenRecordset(sSQL)
If rstBrand.RecordCount > 0 Then
Do While rstBrand.EOF <> True
sBrand = rstBrand.Fields("Brand")
Debug.Print sBrand
sSQL = "SELECT Model FROM tblTest WHERE ((Brand) = '" & sBrand & "' AND (UK) Is Null) GROUP BY Model ORDER BY Model"
Set rstModel = db.OpenRecordset(sSQL)
If rstModel.RecordCount > 0 Then
'determines current maximum integer assigned to this brand/model
If DCount("[UK]", "tblTest", "[Brand] = '" & sBrand & "' AND [Model] = '" & rstModel.Fields("Model") & "'") = 0 Then
iMax = 1
Else
iMax = CInt(Mid(DMax("UK", "tblTest", "[Brand] = '" & sBrand & "' AND [Model] = '" & rstModel.Fields("Model") & "'"), 3, 4)) + 1
End If
Do While rstModel.EOF <> True
sModel = rstModel.Fields("Model")
Debug.Print " " & sModel
sSQL = "SELECT Version, UK FROM tblTest WHERE ((Brand) = '" & sBrand & "' AND (Model) = '" & sModel & "' AND (UK) Is Null)"
Set rstVersion = db.OpenRecordset(sSQL)
If rstVersion.RecordCount <> 0 Then
'determines current maximum integer assigned to this version
If DCount("[UK]", "tblTest", "[Brand] = '" & sBrand & "' AND [Model] = '" & sModel & "'") = 0 Then
iVersion = 1
Else
iVersion = CInt(Right(DMax("UK", "tblTest", "[Brand] = '" & sBrand & "' AND [Model] = '" & sModel & "'"), 2)) + 1
End If
Do While rstVersion.EOF <> True
sVersion = rstVersion.Fields("Version")
Debug.Print " " & sVersion
sUK = UCase(Left(sBrand, 2)) & Right("0000" & iMax, 4) & "_" & Right("00" & iVersion, 2)
rstVersion.Edit
rstVersion!UK = sUK
rstVersion.Update
iVersion = iVersion + 1
Debug.Print " " & sUK
rstVersion.MoveNext
Loop
End If
rstVersion.Close
iMax = iMax + 1
rstModel.MoveNext
Loop
End If
rstModel.Close
rstBrand.MoveNext
Loop
End If
rstBrand.Close
Set db = Nothing
CorriCorrado
Profilo
| Junior Member
86
messaggi | Data Invio:
mar 2 lug 2013 - 09:59
Ciao,
funziona?
Corrado
sergranero
Profilo
| Junior Member
100
messaggi | Data Invio:
mar 2 lug 2013 - 10:34
sI..SI... infatti l'ho caricato apposta perchè può essere d'aiuto ad altri utenti
Ciao
Torna su
Stanze Forum
Elenco Threads
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?
Dopo esserti registrato potrai chiedere
aiuto sul nostro
Forum
oppure aiutare gli altri
Consulta le
Stanze
disponibili.
Registrati ora !