Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding a Number to a string

Status
Not open for further replies.

simian101

MIS
Nov 16, 2007
113
US
I need to combine string with a consecutive number.

Like

Option1
Option2
Option3
etc.

Is there a way to do it without using a cursor?

Somthing like

select field1, 'option' + MagicNumber as OptNum

Thanks

Simi




 
Need more info about what you're trying to do. Give sample data and example expected output.
 
I am setting up a program that has a table that hold data to be used in drop down fields.

The table has to be formatted as

field1 field2
******* ********
option1 Bill
option2 Tom
option3 Sam

I have an existing table with field2 in it all ready.

I would like to do just do an append/insert query that appends

'Option' + str(NUMBER), NameField

I was hoping there was a way to do it without having to go line by line.

Thanks

Simi

 
I found an answer...

It uses a sub query.

SELECT [VECODE]
,[VENUM]
,[VEDESC]
,[VEACCT]
,[VECOMP]
,[VESUB]
,(SELECT COUNT(*) FROM [vhemast] e2 WHERE e2.[VENUM]<= e.[VENUM]) AS MyOption1
,'Option' + ltrim(str((SELECT COUNT(*) FROM [vhemast] e2 WHERE e2.[VENUM]<= e.[VENUM]))) AS MyOption2
,ltrim(str([VENUM])) + '-' + [VEDESC] as test
FROM [RepliconTemp].[dbo].[vhemast] e
order by myoption1

Thanks

Simi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top