February 8, 2011 at 10:02 am
I have the following data to be converted. Can someone help me pl?
tblA contains
CustomerKey NVarchar(100)
CustomerID NVarchar(50)
CustomerKey CustomerID
000098878787 284005
000089898989 284005
000565656565 084005
000012323232 004003
I would like to convert the above to
CustomerKey Bigint
CustomerId int
Any help will be great.
tx
ram
February 8, 2011 at 10:14 am
Ram this seemed a little too straight forward...simple CONVERT commands seem to work fine for me...what am i missing on your question?
With tblA(CustomerKey,CustomerID)
As
(
SELECT N'000098878787',N'284005' UNION ALL
SELECT N'000089898989',N'284005' UNION ALL
SELECT N'000565656565',N'084005' UNION ALL
SELECT N'000012323232',N'004003'
)
SELECT
CONVERT(BIGINT,CustomerKey) As CustomerKey,
CONVERT(INT,CustomerID) As CustomerID
FROM tblA
Lowell
February 8, 2011 at 12:22 pm
Hi, thanks for your help.
I did convert the same but gettign the following error.
Error Converting data type nvarchar to bigint
February 8, 2011 at 12:34 pm
Sorry, I didn't read your msg. I did mess the question here.
as you are aware, the following are the input data.
tblA contains
CustomerKey bigint
CustomerID varchar(25)
CustomerKey CustomerID
98878787 284005
89898989 284005
56565 084005
2323232 004003
I would like to convert the customer key to nvarchar datatype, as follows.
CustomerKey
00098878787
00089898989
00000056565
00002323232
The customer key length may change so I have to precede them with '0's.
Again, sorry, I didn't read your msg,
best
ram
February 8, 2011 at 12:44 pm
ok, you want the reverse...you have a bigint field, but want preceding zeros.
the max bigint value is 9,223,372,036,854,775,807
9223372036854775807
|______19 digits___|
123456789012345678
that's 19 digits.... assuming you want up to 18 preceding zeros, you would do something like this:
SELECT RIGHT( N'000000000000000000' + CONVERT(Nvarchar(30),CustomerKey),19) From MyTable
with that example in place, why, oh why do you want preceding zerso...and to display bigint, you need way to many to make it consistent and comfortable/readable.
Lowell
February 8, 2011 at 12:51 pm
Thanks and you are the Best
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply