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 2005 Forums
 Transact-SQL (2005)
 Select Stmt

Author  Topic 

sherilynmayer
Starting Member

1 Post

Posted - 2008-03-27 : 07:38:26
How do I use the select statement to create a blank field in a temp table, so I can use the update statement to populate the data later.

I tried [Select ' ' as field] and then tried the update statement to later populate data and I am getting the following error:
Msg 8152, Level 16, State 14, Line 1
String or binary data would be truncated.
The statement has been terminated.

Please help

elancaster
A very urgent SQL Yakette

1208 Posts

Posted - 2008-03-27 : 07:53:33
did you create your temp table using SELECT INTO ? I suspect you probably did, as this would mean you implicitly created the column [field] with a zero length (because that's what you set it to initially). Then when you try and update it to something longer the new value is too long to fit in that column. make sense?

if you create the temp table first with the column length you want, you won't have that problem

Em
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-03-27 : 07:54:10
What should be the size of the field?

You should do something like this:

select convert(varchar(<size>), '') as SomeCol into #temp
from <sometable>


Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-03-27 : 15:12:41
or create the temp table using CREATE TABLE stmt according to structure you want and use INSERT INTO ..SELECT to enter values.
Go to Top of Page
   

- Advertisement -