Showing posts with label hidoes. Show all posts
Showing posts with label hidoes. Show all posts

Thursday, March 29, 2012

Does SQL Server handles time zone difference?

Hi
Does SQL Server 200 handles time zone?
We want to transfer all data to another server periodically that is situated
at a different time zone.
Also some time we restore complete database to second server.
we want to keep correct time stored with the data as per the time zone where
second sql server is present.
how can this be achieved?
Regards
Lalit Bhatia
Hi Lalit
SQL Server is storing the time according to the time that it is
getting from the OS. If you modify the time at the OS level, then SQL
Server will NOT modify the values that it already has in the tables.
Personally I wouldn't want it to do so. I want the data to be
consistent and I wouldn't want it to updates all the records twice a
year because of day light savings.
If you have a requirement to store data in a way that users will see
different time according to the server's time zone, then you can store
the time as UCT time and present it as local time. You can use the
function GETUTCDATE() together with DATEADD() and GETDATE() when ever
you insert, modify or present the data. This way the data at the table
will be the same, but if you move the data to a different server in a
different time zone, then users will see the data that is adjusted to
there time zone. Be aware that this might be confusing. If a person
in N.Y is talking with a person in L.A about one of the records, each
one of them will see a different time.
Lalit wrote:
> Hi
> Does SQL Server 200 handles time zone?
> We want to transfer all data to another server periodically that is situated
> at a different time zone.
> Also some time we restore complete database to second server.
> we want to keep correct time stored with the data as per the time zone where
> second sql server is present.
> how can this be achieved?
>
> Regards
> Lalit Bhatia

Does SQL Server handles time zone difference?

Hi
Does SQL Server 200 handles time zone?
We want to transfer all data to another server periodically that is situated
at a different time zone.
Also some time we restore complete database to second server.
we want to keep correct time stored with the data as per the time zone where
second sql server is present.
how can this be achieved?
Regards
Lalit BhatiaHi Lalit
SQL Server is storing the time according to the time that it is
getting from the OS. If you modify the time at the OS level, then SQL
Server will NOT modify the values that it already has in the tables.
Personally I wouldn't want it to do so. I want the data to be
consistent and I wouldn't want it to updates all the records twice a
year because of day light savings.
If you have a requirement to store data in a way that users will see
different time according to the server's time zone, then you can store
the time as UCT time and present it as local time. You can use the
function GETUTCDATE() together with DATEADD() and GETDATE() when ever
you insert, modify or present the data. This way the data at the table
will be the same, but if you move the data to a different server in a
different time zone, then users will see the data that is adjusted to
there time zone. Be aware that this might be confusing. If a person
in N.Y is talking with a person in L.A about one of the records, each
one of them will see a different time.
Lalit wrote:
> Hi
> Does SQL Server 200 handles time zone?
> We want to transfer all data to another server periodically that is situat
ed
> at a different time zone.
> Also some time we restore complete database to second server.
> we want to keep correct time stored with the data as per the time zone whe
re
> second sql server is present.
> how can this be achieved?
>
> Regards
> Lalit Bhatia

Sunday, February 26, 2012

Does anyone have an ForEachColumn Procedure?

Hi

Does anyone have an ForEachColumn Procedure?
(a bit like the MSforeachdb and MSforeachtable sps)

This should be quite generic for anyone working with real life data coming in from other systems.

I need to fill out the rows with missing values in historic records from the previous current record.
(sometimes even from a previous historic record)
And sometimes the current record doesn't have data in the field, so I shouldn't get the data from current -1.

Can solve most of the complexities of the filling out part.

But it needs to be applied for (most of) my 57 columns,and then there is even some differently formatted data just beyond the horizon, so maybe I should try to get a more generic applicable solution.

Did anyone try a ForEachColumnExcept procedure

CREATE PROCEDURE ForEachColumnExcept
@.TableName varchar(200)
, @.ExceptionList varchar(8000) = '' -- the few ones to exclude
, @.DelimterInExceptionlist varchar(10) = ','
AS
...
END

the difficulty here is getting the columns from the databse's data-dictionary
)haven't done that before, but I think I'll find that out.

Or even:

CREATE PROCEDURE ForEachColumnInList
@.TableName varchar(200)
, @.ColumnList varchar(8000) -- all the ones to include
, @.DelimterInColumnList varchar(10) = ','
AS
...
END

Cheers

Drionot sure what u finally want to do with the column list, this will however generate a column list & data type based on params u declared

set @.ExceptionList = ','+ @.ExceptionList + ','
select Column_name,Data_Type from information_schema.columns
where table_name=@.TableName and column_name not in (case when charindex(','+column_name+',',@.ExceptionList) > 0 then column_name else '' end)