Solved

Convert function error

Posted on 2004-10-19
8
393 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
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…

730 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