Solved

Convert function error

Posted on 2004-10-19
8
389 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
  • 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
 
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Database tuning – How to start and what to tune. This question is frequently asked by many people, both online and offline. There is no hard and fast rule-of-thumb for performance tuning, however, before beginning the tuning process one should a…
APEX (Application Express) is used to develop a web application from Oracle. SQL Workshop is one of the tools that comes with Oracle APEX to query or modify the database objects or to make any changes to the structure.
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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now