proudpaki9
asked on
Adding 2 coulmns into 1
Hello:
I have 2 fields Field1(int) and Filed2 (bigint) and here is the statement:
Update [dbo].[591726273]
set [LINK] = [Field1] + left([Field2],18)
LINK is the data type bigint
I am getting the following error message:
Server: Msg 248, Level 16, State 1, Line 1
The conversion of the varchar value '200705311867085988' overflowed an int column. Maximum integer value exceeded.
The statement has been terminated.
How do I fix this problem?
Thank you.
I have 2 fields Field1(int) and Filed2 (bigint) and here is the statement:
Update [dbo].[591726273]
set [LINK] = [Field1] + left([Field2],18)
LINK is the data type bigint
I am getting the following error message:
Server: Msg 248, Level 16, State 1, Line 1
The conversion of the varchar value '200705311867085988' overflowed an int column. Maximum integer value exceeded.
The statement has been terminated.
How do I fix this problem?
Thank you.
ASKER
I tried the statement:
Update [dbo].[562070036]
set [LINK]= Cast([Field1] As Bigint)+ left([Field2],18)
The result:
Its only updating the field with the left 18 of field2, but not updaing with the field1 at all.
Total length for the field2 = 9
Total length for the field1 = 20
Please advise.
Thank you.
Update [dbo].[562070036]
set [LINK]= Cast([Field1] As Bigint)+ left([Field2],18)
The result:
Its only updating the field with the left 18 of field2, but not updaing with the field1 at all.
Total length for the field2 = 9
Total length for the field1 = 20
Please advise.
Thank you.
Try:
Update [dbo].[562070036]
set [LINK]= Cast([Field1] As Bigint)+ CAST(left([Field2],18) AS BIGINT)
I've noticed that SQL has some oddities in picking how it converts values.
Update [dbo].[562070036]
set [LINK]= Cast([Field1] As Bigint)+ CAST(left([Field2],18) AS BIGINT)
I've noticed that SQL has some oddities in picking how it converts values.
ASKER
Still doing the same only picking up the field2, 18.
Thanks
Thanks
Are there any NULL values in [Field1]?
Let's go brute force and use the DECIMAL type
Update [dbo].[562070036]
set [LINK]= Cast([Field1] As DECIMAL(10,0))+ CAST(left([Field2],18) AS DECIMAL(21,0))
Let's go brute force and use the DECIMAL type
Update [dbo].[562070036]
set [LINK]= Cast([Field1] As DECIMAL(10,0))+ CAST(left([Field2],18) AS DECIMAL(21,0))
ASKER
Same thing again.
Thanks
Thanks
ASKER
No nulls in the fields.
I'm going to try some queries in my Query Analyzer. Can you send me a 1/2 dozen sample rows with Field1 and Field2 values?
ASKER
LINK field(bigint)
Field1 (int) Field2(bigint)
218421091 2006010508822916570
214992248 2006011108827054820
205497164 2006011311827200890
207773513 2006011318296207860
216251984 2006020618312128630
212400308 2006022218323990690
Thanks
Field1 (int) Field2(bigint)
218421091 2006010508822916570
214992248 2006011108827054820
205497164 2006011311827200890
207773513 2006011318296207860
216251984 2006020618312128630
212400308 2006022218323990690
Thanks
Well I ran the following queries and they all worked.
CREATE TABLE #Ints (
LINK BIGINT NULL,
Field1 INT NULL,
Field2 BIGINT NULL
)
SET NOCOUNT ON
INSERT INTO #Ints (Field1, Field2) VALUES (218421091,200601050882291 6570)
INSERT INTO #Ints (Field1, Field2) VALUES (214992248,200601110882705 4820)
INSERT INTO #Ints (Field1, Field2) VALUES (205497164,200601131182720 0890)
INSERT INTO #Ints (Field1, Field2) VALUES (207773513,200601131829620 7860)
INSERT INTO #Ints (Field1, Field2) VALUES (216251984,200602061831212 8630)
INSERT INTO #Ints (Field1, Field2) VALUES (212400308,200602221832399 0690)
-- The following line fails
--UPDATE #Ints SET LINK = Field1+LEFT(Field2,18) FROM #Ints
UPDATE #Ints SET LINK = CAST(Field1 AS BIGINT)+LEFT(Field2,18) FROM #Ints
SELECT * FROM #Ints
UPDATE #Ints SET LINK = Field1+(Field2/10) FROM #Ints
SELECT * FROM #Ints
UPDATE #Ints SET LINK = Field1+CAST(LEFT(Field2,18 ) AS BIGINT) FROM #Ints
SELECT * FROM #Ints
DROP TABLE #Ints
CREATE TABLE #Ints (
LINK BIGINT NULL,
Field1 INT NULL,
Field2 BIGINT NULL
)
SET NOCOUNT ON
INSERT INTO #Ints (Field1, Field2) VALUES (218421091,200601050882291
INSERT INTO #Ints (Field1, Field2) VALUES (214992248,200601110882705
INSERT INTO #Ints (Field1, Field2) VALUES (205497164,200601131182720
INSERT INTO #Ints (Field1, Field2) VALUES (207773513,200601131829620
INSERT INTO #Ints (Field1, Field2) VALUES (216251984,200602061831212
INSERT INTO #Ints (Field1, Field2) VALUES (212400308,200602221832399
-- The following line fails
--UPDATE #Ints SET LINK = Field1+LEFT(Field2,18) FROM #Ints
UPDATE #Ints SET LINK = CAST(Field1 AS BIGINT)+LEFT(Field2,18) FROM #Ints
SELECT * FROM #Ints
UPDATE #Ints SET LINK = Field1+(Field2/10) FROM #Ints
SELECT * FROM #Ints
UPDATE #Ints SET LINK = Field1+CAST(LEFT(Field2,18
SELECT * FROM #Ints
DROP TABLE #Ints
ASKER
The method use is upadtign the temp table. How can I update the real table with the field?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I tried your suggestions still not giving the value I am looking for.
Thanks
Thanks
Hmm, well I am stumped. I can't replicate your error. I've tried my answer on SQL 2000 and SQL 2005 and they both work correctly.
set [LINK] = CAST([Field1] AS BIGINT) + left([Field2],18)