Solved

Convert function error

Posted on 2004-10-19
8
390 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
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…

914 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

12 Experts available now in Live!

Get 1:1 Help Now