Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Null As Column?

Author  Topic 

karuna
Aged Yak Warrior

582 Posts

Posted - 2005-11-14 : 12:54:59
This query

select 'col1' as Col1,null as col2 into #test
insert into #test
select 'col1','fkljasfhajksfa'


gives me an error stating "Syntax error converting the varchar value 'fkljasfhajksfa' to a column of data type int"

How do I solve this?

Thanks


Karunakaran

nr
SQLTeam MVY

12543 Posts

Posted - 2005-11-14 : 13:20:04
select 'col1' as Col1,convert(varchar(20),null) as col2 into #test
insert into #test
select 'col1','fkljasfhajksfa'


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

karuna
Aged Yak Warrior

582 Posts

Posted - 2005-11-14 : 13:37:23
quote:
Originally posted by nr

select 'col1' as Col1,convert(varchar(20),null) as col2 into #test
insert into #test
select 'col1','fkljasfhajksfa'



Solved it with Cast..

Thanks nr

Karunakaran
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-11-15 : 01:51:23
>>gives me an error stating "Syntax error converting the varchar value 'fkljasfhajksfa' to a column of data type int"

It is because col2 will be int by default

You can also use this

select 'col1' as Col1,' ' as col2 into #test
insert into #test
select 'col1','fkljasfhajksfa'


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

karuna
Aged Yak Warrior

582 Posts

Posted - 2005-11-15 : 05:09:58
quote:
Originally posted by madhivanan


You can also use this

select 'col1' as Col1,' ' as col2 into #test
insert into #test
select 'col1','fkljasfhajksfa'



Thats how I tried it first, but it was giving string truncation error because for col2 the length it takes is 1.

Thanks

Karunakaran
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-11-15 : 06:35:18
Well. In that case you need to specify the data length

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -