Thursday, March 8, 2012
Convert string to hex to int
convert this to hex and then to int. How do I do this?
Data in my table:
139D5
6374
63B2
620B
ABC7
6391
6FA6
604A
139D6
This should be ideally
0x139D5
0x6374
0x63B2
0x620B
0xABC7
0x6391
0x6FA6
0x604A
0x139D6
How do I convert 139D5 to 0x139D5 so that I can cast it as an integer?
declare @.a varchar (1000)
set @.a='139D5'
select cast(cast (@.a as varbinary) as int)
select cast (0x 139D5 as int)
These two stmts give different results. Only the second one is correct.
Please help.
*** Sent via Developersdex http://www.examnotes.net ***
Don't just participate in USENET...get rewarded for it!Why did you save hexadecimal value to string? Instead you can directly
store it as integer
Madhivanan|||Hi
Check out this previous post:
http://tinyurl.com/6syea
John
"male hit" wrote:
> My table has some hexadecimal data but stored as string. I want to
> convert this to hex and then to int. How do I do this?
> Data in my table:
> 139D5
> 6374
> 63B2
> 620B
> ABC7
> 6391
> 6FA6
> 604A
> 139D6
> This should be ideally
> 0x139D5
> 0x6374
> 0x63B2
> 0x620B
> 0xABC7
> 0x6391
> 0x6FA6
> 0x604A
> 0x139D6
> How do I convert 139D5 to 0x139D5 so that I can cast it as an integer?
> declare @.a varchar (1000)
> set @.a='139D5'
> select cast(cast (@.a as varbinary) as int)
> select cast (0x 139D5 as int)
> These two stmts give different results. Only the second one is correct.
> Please help.
> *** Sent via Developersdex http://www.examnotes.net ***
> Don't just participate in USENET...get rewarded for it!
>
Wednesday, March 7, 2012
Convert serial date to date string
I have serial dates (39111.501539) in a table and I would like to
convert them to this string format : 1/22/2007 12:31:05 PM. Any
suggestions would be greatly appreciated. The problem exists when I
have to maually load the database tables, I get the serial dates
inserted into the table.
Thank you.
select convert(datetime, 39111.501539)
Returns: 2007-01-31 12:02:12.967
To manage the format you can use substring and various formats, such as:
select stuff(convert(nvarchar(100),convert(datetime, 39111.501539), 101)+
' ' + substring(convert(nvarchar(100),convert(datetime, 39111.501539),
109),13, 20),
20, 4, ' ')
Returns: 01/31/2007 12:02:12 PM
RLF
"Rnt6872" <r_fordjr@.msn.com> wrote in message
news:1172848377.693987.193700@.t69g2000cwt.googlegr oups.com...
> Hi All,
> I have serial dates (39111.501539) in a table and I would like to
> convert them to this string format : 1/22/2007 12:31:05 PM. Any
> suggestions would be greatly appreciated. The problem exists when I
> have to maually load the database tables, I get the serial dates
> inserted into the table.
> Thank you.
>
|||On Mar 2, 10:57 am, "Russell Fields" <russellfie...@.nomail.com> wrote:
> select convert(datetime, 39111.501539)
> Returns: 2007-01-31 12:02:12.967
> To manage the format you can use substring and various formats, such as:
> select stuff(convert(nvarchar(100),convert(datetime, 39111.501539), 101)+
> ' ' + substring(convert(nvarchar(100),convert(datetime, 39111.501539),
> 109),13, 20),
> 20, 4, ' ')
> Returns: 01/31/2007 12:02:12 PM
> RLF
> "Rnt6872" <r_for...@.msn.com> wrote in message
> news:1172848377.693987.193700@.t69g2000cwt.googlegr oups.com...
>
>
> - Show quoted text -
Thank you. Very much!!!!
Convert serial date to date string
I have serial dates (39111.501539) in a table and I would like to
convert them to this string format : 1/22/2007 12:31:05 PM. Any
suggestions would be greatly appreciated. The problem exists when I
have to maually load the database tables, I get the serial dates
inserted into the table.
Thank you.select convert(datetime, 39111.501539)
Returns: 2007-01-31 12:02:12.967
To manage the format you can use substring and various formats, such as:
select stuff(convert(nvarchar(100),convert(date
time, 39111.501539), 101)+
' ' + substring(convert(nvarchar(100),convert(
datetime, 39111.501539),
109),13, 20),
20, 4, ' ')
Returns: 01/31/2007 12:02:12 PM
RLF
"Rnt6872" <r_fordjr@.msn.com> wrote in message
news:1172848377.693987.193700@.t69g2000cwt.googlegroups.com...
> Hi All,
> I have serial dates (39111.501539) in a table and I would like to
> convert them to this string format : 1/22/2007 12:31:05 PM. Any
> suggestions would be greatly appreciated. The problem exists when I
> have to maually load the database tables, I get the serial dates
> inserted into the table.
> Thank you.
>|||On Mar 2, 10:57 am, "Russell Fields" <russellfie...@.nomail.com> wrote:
> select convert(datetime, 39111.501539)
> Returns: 2007-01-31 12:02:12.967
> To manage the format you can use substring and various formats, such as:
> select stuff(convert(nvarchar(100),convert(date
time, 39111.501539), 101)+
> ' ' + substring(convert(nvarchar(100),convert(
datetime, 39111.501539),
> 109),13, 20),
> 20, 4, ' ')
> Returns: 01/31/2007 12:02:12 PM
> RLF
> "Rnt6872" <r_for...@.msn.com> wrote in message
> news:1172848377.693987.193700@.t69g2000cwt.googlegroups.com...
>
>
>
> - Show quoted text -
Thank you. Very much!!!!
Sunday, February 19, 2012
Convert Int to String and add to another String
I have a SP where I grab a value from an Identity field and then I want to
convert it to a String and add it to another string.
Only the @.lname stores in the @.CustNum. From what I understand STR should
change it to a string. Any help would be great.
Here is the example
Declare @.lname varchar(10)
Declare @.lnameid int
declare @.CustNum varchar(15)
INSERT INTO ClientGenerator(ClientCode) VALUES (@.Lname + @.Fname)
SELECT @.lnameid=SCOPE_IDENTITY()
Set @.CustNum = @.lname + STR(@.lnameid)Take a look at CAST,CONVERT system functions in the BOL
"Vear" <Vear@.discussions.microsoft.com> wrote in message
news:EDEDC80E-A41E-4DA0-953C-0E4A61F198CB@.microsoft.com...
> Hi,
> I have a SP where I grab a value from an Identity field and then I want to
> convert it to a String and add it to another string.
> Only the @.lname stores in the @.CustNum. From what I understand STR should
> change it to a string. Any help would be great.
> Here is the example
> Declare @.lname varchar(10)
> Declare @.lnameid int
> declare @.CustNum varchar(15)
> INSERT INTO ClientGenerator(ClientCode) VALUES (@.Lname + @.Fname)
> SELECT @.lnameid=SCOPE_IDENTITY()
> Set @.CustNum = @.lname + STR(@.lnameid)|||Thanks, Cast worked Great!!
"Uri Dimant" wrote:
> Take a look at CAST,CONVERT system functions in the BOL
> "Vear" <Vear@.discussions.microsoft.com> wrote in message
> news:EDEDC80E-A41E-4DA0-953C-0E4A61F198CB@.microsoft.com...
>
>
Friday, February 10, 2012
convert date to MMDDYYYY
I can't seem to find an answer to this anywhere else: I need to
convert a datestamp to the following format: MMDDYYYY. I've found
solutions to convert it to many different kids of formats, but not one
that allows me to enter the positions of the month, day and year.
Anyone have any ideas?
Thanks,
Mike<mscgloss@.yahoo.com> wrote in message
news:1095699247.330433.190810@.k26g2000oda.googlegr oups.com...
> Hello All,
> I can't seem to find an answer to this anywhere else: I need to
> convert a datestamp to the following format: MMDDYYYY. I've found
> solutions to convert it to many different kids of formats, but not one
> that allows me to enter the positions of the month, day and year.
> Anyone have any ideas?
> Thanks,
> Mike
Here's one way:
select replace(convert(char(10), getdate(), 101), '/', '')
Alternatively, you could format it in your client application if that makes
sense in your environment.
Simon