| Author |
Topic |
|
Studevs
Starting Member
15 Posts |
Posted - 2010-02-19 : 05:50:54
|
| Dear All,I have a table with two columns:name and number...the type of both columns is varchar.now how can ik select the both columns buth the value of column number most be returned in ascii.Please some help. Thanks in advance |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-19 : 05:57:34
|
| use ASCII() function. you might have to loop over entire length of number to convert all characters to ASCII.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
Studevs
Starting Member
15 Posts |
Posted - 2010-02-19 : 06:01:58
|
Hi visakh16,How can i loop over the length of the number column?quote: Originally posted by visakh16 use ASCII() function. you might have to loop over entire length of number to convert all characters to ASCII.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
|
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-19 : 06:03:13
|
| are you using sql 2005?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-02-19 : 06:05:15
|
quote: Originally posted by Studevs Dear All,I have a table with two columns:name and number...the type of both columns is varchar.now how can ik select the both columns buth the value of column number most be returned in ascii.Please some help. Thanks in advance
Post some sample data with expected resultMadhivananFailing to plan is Planning to fail |
 |
|
|
Studevs
Starting Member
15 Posts |
Posted - 2010-02-19 : 06:42:23
|
Yes it's sql server 2005quote: Originally posted by visakh16 are you using sql 2005?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
|
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-02-19 : 07:21:14
|
Have you seen my previous reply? MadhivananFailing to plan is Planning to fail |
 |
|
|
Studevs
Starting Member
15 Posts |
Posted - 2010-02-19 : 07:31:37
|
Hi madhivanan,This is the code:CREATE TABLE [dbo].[customer]( [name] [varchar](50) NULL, [number] [varchar](50) NULL) ON [PRIMARY]GOSET ANSI_PADDING OFFGO INSERT INTO [qvtelemetrie].[dbo].[customer] ([name] ,[number]) VALUES ('name','3214')GOquote: Originally posted by madhivanan Have you seen my previous reply? MadhivananFailing to plan is Planning to fail
|
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-02-19 : 07:32:42
|
quote: Originally posted by Studevs Hi madhivanan,This is the code:CREATE TABLE [dbo].[customer]( [name] [varchar](50) NULL, [number] [varchar](50) NULL) ON [PRIMARY]GOSET ANSI_PADDING OFFGO INSERT INTO [qvtelemetrie].[dbo].[customer] ([name] ,[number]) VALUES ('name','3214')GOquote: Originally posted by madhivanan Have you seen my previous reply? MadhivananFailing to plan is Planning to fail
What is your expected result?MadhivananFailing to plan is Planning to fail |
 |
|
|
Studevs
Starting Member
15 Posts |
Posted - 2010-02-19 : 07:42:45
|
i want a select statement wich returns the 'name' column data just like it is and the ascii code of the 'number' column dataquote: Originally posted by madhivanan
quote: Originally posted by Studevs Hi madhivanan,This is the code:CREATE TABLE [dbo].[customer]( [name] [varchar](50) NULL, [number] [varchar](50) NULL) ON [PRIMARY]GOSET ANSI_PADDING OFFGO INSERT INTO [qvtelemetrie].[dbo].[customer] ([name] ,[number]) VALUES ('name','3214')GOquote: Originally posted by madhivanan Have you seen my previous reply? MadhivananFailing to plan is Planning to fail
What is your expected result?MadhivananFailing to plan is Planning to fail
|
 |
|
|
vaibhavktiwari83
Aged Yak Warrior
843 Posts |
Posted - 2010-02-19 : 08:08:35
|
| ASCII code for the number 1234 will give you the ascii code of 1 only.what you needVabhav T |
 |
|
|
Studevs
Starting Member
15 Posts |
Posted - 2010-02-19 : 08:32:25
|
I need the ascii of the entire string, not only from first characterquote: Originally posted by vaibhavktiwari83 ASCII code for the number 1234 will give you the ascii code of 1 only.what you needVabhav T
|
 |
|
|
vaibhavktiwari83
Aged Yak Warrior
843 Posts |
Posted - 2010-02-19 : 08:50:49
|
| ascii is for only one character.what you want you want to concatenate all the ascii code for each character or what.Vabhav T |
 |
|
|
Studevs
Starting Member
15 Posts |
Posted - 2010-02-19 : 09:11:24
|
Hi Vabhav,Thanks,yes that's exatly what i want :)quote: Originally posted by vaibhavktiwari83 ascii is for only one character.what you want you want to concatenate all the ascii code for each character or what.Vabhav T
|
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-02-19 : 09:17:12
|
quote: Originally posted by Studevs Hi Vabhav,Thanks,yes that's exatly what i want :)quote: Originally posted by vaibhavktiwari83 ascii is for only one character.what you want you want to concatenate all the ascii code for each character or what.Vabhav T
Why do you want to do this?MadhivananFailing to plan is Planning to fail |
 |
|
|
Studevs
Starting Member
15 Posts |
Posted - 2010-02-19 : 09:20:35
|
| it's a requirement |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-19 : 09:44:41
|
quote: Originally posted by Studevs it's a requirement
create a function like thisCREATE FUNCTION dbo.GetAsciiValue(@str varchar(100))RETURNS varchar(1000)ASBEGINDECLARE @res varchar(1000)SELECT @res=COALESCE(@res,'')+CAST(ASCII(SUBSTRING(@str,number,1)) AS varchar(5))FROM master..spt_valuesWHERE type='p'AND number BETWEEN 1 AND LEN(@str)RETURN @resENDthen use it likeselect name,number,dbo.GetAsciiValue(number) AS AsciiEqvfrom yourtable ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
Studevs
Starting Member
15 Posts |
Posted - 2010-02-19 : 10:02:28
|
Dear visakh16,This works great , thanks a lot for your great help.quote: Originally posted by visakh16
quote: Originally posted by Studevs it's a requirement
create a function like thisCREATE FUNCTION dbo.GetAsciiValue(@str varchar(100))RETURNS varchar(1000)ASBEGINDECLARE @res varchar(1000)SELECT @res=COALESCE(@res,'')+CAST(ASCII(SUBSTRING(@str,number,1)) AS varchar(5))FROM master..spt_valuesWHERE type='p'AND number BETWEEN 1 AND LEN(@str)RETURN @resENDthen use it likeselect name,number,dbo.GetAsciiValue(number) AS AsciiEqvfrom yourtable ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
|
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-19 : 10:04:00
|
welcome ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|