Solved

Convert function error

Posted on 2004-10-19
8
395 Views
Last Modified: 2008-02-01
Please help me to solve this error:

insert into table2
(_INTERNID, _STAMP2, _STAMP3, _TYPE)
select _INTERNID, _STAMP2, @result, 'Strategy' from table1

Server: Msg 260, Level 16, State 1, Line 10
Disallowed implicit conversion from data type varchar to data type binary, table 'db.dbo.RMPII', column '_STAMP3'. Use the CONVERT function to run this query.

Any idea?
0
Comment
Question by:Vasi04
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 

Author Comment

by:Vasi04
ID: 12355456
'db.dbo.RMPII' = table2
0
 

Assisted Solution

by:a_tya
a_tya earned 200 total points
ID: 12355561
What datatype is "_STAMP3" field? if it is varchar try this:
insert into table2
(_INTERNID, _STAMP2, _STAMP3, _TYPE)
select _INTERNID, _STAMP2, convert(varchar(100), @result), 'Strategy' from table1
0
 
LVL 1

Expert Comment

by:giriky99
ID: 12355578
Hi,

You can use the  your query like this..


case 1..If  _STAMP3 column in Table2 Datatype is varchar(50)

insert into table2
(_INTERNID, _STAMP2, _STAMP3, _TYPE)
select _INTERNID, _STAMP2, convert(@result,varchar(50)), 'Strategy' from table1

case 1..If  _STAMP3 column in Table2 Datatype is int

insert into table2
(_INTERNID, _STAMP2, _STAMP3, _TYPE)
select _INTERNID, _STAMP2, convert(@result,int), 'Strategy' from table1


case 1..If  _STAMP3 column in Table2 Datatype is Money
insert into table2
(_INTERNID, _STAMP2, _STAMP3, _TYPE)
select _INTERNID, _STAMP2, convert(@result,Money), 'Strategy' from table1

Try the above statements....Also check the data in that @result  variable .


 



0
Do you have a plan for Continuity?

It's inevitable. People leave organizations creating a gap in your service. That's where Percona comes in.

See how Pepper.com relies on Percona to:
-Manage their database
-Guarantee data safety and protection
-Provide database expertise that is available for any situation

 
LVL 1

Expert Comment

by:giriky99
ID: 12355611
Hi,

You can use  your query like this..


case 1..If  _STAMP3 column in Table2 Datatype is varchar(50)

insert into table2
(_INTERNID, _STAMP2, _STAMP3, _TYPE)
select _INTERNID, _STAMP2, convert(@result,varchar(50)), 'Strategy' from table1

case 2..If  _STAMP3 column in Table2 Datatype is int

insert into table2
(_INTERNID, _STAMP2, _STAMP3, _TYPE)
select _INTERNID, _STAMP2, convert(@result,int), 'Strategy' from table1


case 3..If  _STAMP3 column in Table2 Datatype is Money
insert into table2
(_INTERNID, _STAMP2, _STAMP3, _TYPE)
select _INTERNID, _STAMP2, convert(@result,Money), 'Strategy' from table1

Try the above statements....Also check the data in that @result  variable .
0
 

Author Comment

by:Vasi04
ID: 12355618
Hi _stamp3 is binary. I used this way cast (@result as binary). but still get error. @result is some alphanumeric B5DK3YBZP

I am running this query in QA:
------------------------------------
declare @result varchar(100)
declare @hsecs numeric
declare @date datetime

set @hsecs = 1
set @date = getdate()
exec shortstamp @date, @hsecs, @result OUTPUT
select @result

insert into table2
(_INTERNID, _CHGDATE, _CHGTIME, _STAMP2, _STAMP3, _RMP_TYPE)
select _INTERNID, Convert(varchar(10),getdate(),101), Convert(varchar(10),getdate(),101), _STAMP2, cast(@result as binary), 'Strategy' from table1
-----------------------------------------

Server: Msg 8152, Level 16, State 11, Line 10
String or binary data would be truncated.
The statement has been terminated.
------------------------------------------------

0
 

Expert Comment

by:a_tya
ID: 12355649
please send the table structure for table1 and table2. I need to know what datatypes are you using..
0
 

Expert Comment

by:a_tya
ID: 12355661
my guess is that you are trying to insert a larger field in a smaller one, that's why the data is truncated.
Hope this helps u.
0
 
LVL 1

Accepted Solution

by:
giriky99 earned 300 total points
ID: 12355853
Hi ,

You that @result having alphanumaric values and you are trying insert into binary column.

My suggetion to change the datatype of   _STAMP3 column to Varchar. and the your query.

or
put where condition to check for numaric as below.

insert into table2
(_INTERNID, _CHGDATE, _CHGTIME, _STAMP2, _STAMP3, _RMP_TYPE)
select _INTERNID, Convert(varchar(10),getdate(),101), Convert(varchar(10),getdate(),101), _STAMP2, cast(@result as binary), 'Strategy' from table1 where ISNUMERIC(@result )=1
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As technology users and professionals, we’re always learning. Our universal interest in advancing our knowledge of the trade is unmatched by most industries. It’s a curiosity that makes sense, given the climate of change. Within that, there lies a…
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question