﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2008 / SQL Server Newbies  / Creating a Ref Number usning letters and numbers. / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Tue, 18 Jun 2013 00:39:30 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Creating a Ref Number usning letters and numbers.</title><link>http://www.sqlservercentral.com/Forums/Topic1422041-1292-1.aspx</link><description>Try this, Wayne:[code="sql"]USE Occupancy;WITH BookingsToUpdate AS (	SELECT 		*,		Seq = ROW_NUMBER() OVER (ORDER BY Booking_Skey)  	FROM Bookings)SELECT	Seq, 	Booking_Skey,	BookingNumber = 'B' + RIGHT('0000000' + CAST(Seq AS VARCHAR(8)),8),	AnotherBookingNumber = 'B' + RIGHT('0000000' + CAST(Booking_Skey AS VARCHAR(8)),8)FROM BookingsToUpdate[/code]</description><pubDate>Thu, 21 Feb 2013 03:21:20 GMT</pubDate><dc:creator>ChrisM@Work</dc:creator></item><item><title>RE: Creating a Ref Number usning letters and numbers.</title><link>http://www.sqlservercentral.com/Forums/Topic1422041-1292-1.aspx</link><description>Hi DwainFor some reason that didn't work, but I found another solution.USE OccupancyUpdate tSet BookingNumber = 'B' + Right ('00000000' + CAST (Seq AS varchar (30)), 8)FROM (SELECT *,ROW_NUMBER() OVER (ORDER BY Booking_Skey) AS Seq FROM Bookings)tThanks for your help.</description><pubDate>Thu, 21 Feb 2013 03:04:39 GMT</pubDate><dc:creator>wafw1971</dc:creator></item><item><title>RE: Creating a Ref Number usning letters and numbers.</title><link>http://www.sqlservercentral.com/Forums/Topic1422041-1292-1.aspx</link><description>[quote][b]ChrisM@Work (2/20/2013)[/b][hr][i]Always [/i]run the corresponding SELECT first. It will show you which rows will be updated, and from what to what. The corresponding SELECT for this UPDATE is this:[/quote]+1 INSERTs too!</description><pubDate>Wed, 20 Feb 2013 17:57:17 GMT</pubDate><dc:creator>dwain.c</dc:creator></item><item><title>RE: Creating a Ref Number usning letters and numbers.</title><link>http://www.sqlservercentral.com/Forums/Topic1422041-1292-1.aspx</link><description>[quote][b]wafw1971 (2/20/2013)[/b][hr]I have a column on my database called Booking Number this is to be used on correspondence etc however I don't want it to be Booking Number to be just a 1, I want it to be B000000001. How can I accomplish this?I have tried but it has not worked.USE OccupancyUpdate BookingsSet BookingNumber = 'B' + Right ('00000000' + CAST (BookingNumber AS varchar (30)), 8)WHERE BookingNumber = '0' ThanksWayne[/quote][i]Always [/i]run the corresponding SELECT first. It will show you which rows will be updated, and from what to what. The corresponding SELECT for this UPDATE is this:[code="sql"]SELECT 	BookingNumber,	NewBookingNumber = 'B' + RIGHT ('00000000' + CAST (BookingNumber AS varchar (30)), 8)FROM BookingsWHERE BookingNumber = '0' [/code]So - which rows will be updated? If the rows displayed don't match your requirement, then change the WHERE clause Is the new value correct? If not, then change the expression. You're casting BookingNumber to VARCHAR(30); is it really a 30 digit number? Will the rightmost 8 digits of a 30-digit number be meaningful?</description><pubDate>Wed, 20 Feb 2013 06:18:27 GMT</pubDate><dc:creator>ChrisM@Work</dc:creator></item><item><title>RE: Creating a Ref Number usning letters and numbers.</title><link>http://www.sqlservercentral.com/Forums/Topic1422041-1292-1.aspx</link><description>Is booking number varchar(30) in the DB?If not look at computed columns and stick an extra column on the end of the table with the formula given to convert it to B00000000 etc</description><pubDate>Wed, 20 Feb 2013 05:59:30 GMT</pubDate><dc:creator>anthony.green</dc:creator></item><item><title>Creating a Ref Number usning letters and numbers.</title><link>http://www.sqlservercentral.com/Forums/Topic1422041-1292-1.aspx</link><description>I have a column on my database called Booking Number this is to be used on correspondence etc however I don't want it to be Booking Number to be just a 1, I want it to be B000000001. How can I accomplish this?I have tried but it has not worked.USE OccupancyUpdate BookingsSet BookingNumber = 'B' + Right ('00000000' + CAST (BookingNumber AS varchar (30)), 8)WHERE BookingNumber = '0' ThanksWayne</description><pubDate>Wed, 20 Feb 2013 05:56:18 GMT</pubDate><dc:creator>wafw1971</dc:creator></item></channel></rss>