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)
 Concatenate / Update sql silly

Author  Topic 

Digital
Starting Member

8 Posts

Posted - 2009-02-11 : 05:07:09
Hi all

I have a factsalesweekly table that im going to change to Daily

there is a [Kweek] column numbered 1-100.... for example
i want to update this column to [Kdate]

e.g
kweek kdate
1 = 20090101
2 = 20090102
3 = 20090103

and so on

for the first 31 days what would be the best way to update this so it concatenates looking at each number

cheers

Digital

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-02-11 : 05:10:03
UPDATE FactSalesWeekly
SET kDate = DATEADD(DAY, kWeek, '20081231')



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

Digital
Starting Member

8 Posts

Posted - 2009-02-11 : 05:15:51
sorry still pretty new to sql
i get a error with that
"Implicit conversion from data type datetime to int is not allowed. Use the CONVERT function to run this query."
any ideas of what its trying to do and where i should use the convert

Digital
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-02-11 : 05:18:30
kDate is an INTEGER column, not a DATETIME column?
UPDATE	FactSalesWeekly
SET kDate = CONVERT(CHAR(8), DATEADD(DAY, kWeek, '20081231'), 112)



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

Digital
Starting Member

8 Posts

Posted - 2009-02-11 : 05:26:03
correct
That looks like its done it
hows does that dateadd function work
its good to get answer here but better to understand
Cheers Peso


Digital
Go to Top of Page
   

- Advertisement -