using …

Pure C#

Archive for the ‘Cast’ Category

Cast operators do not obey the distributive law

Posted by esersahin on 31/05/2010


http://blogs.msdn.com/b/ericlippert/archive/2010/05/27/cast-operators-do-not-obey-the-distributive-law.aspx

Posted in C#, Cast | Leave a Comment »

SQL Server / T-SQL Tutorial

Posted by esersahin on 20/03/2009


http://www.java2s.com/Tutorial/SQLServer/CatalogSQLServer.htm

Posted in Cast, Common Table Expressions, Cross-Tabs, CTE, Functions, Instead Of, Pivot Tables, Raiserror, ROW_NUMBER, SQL, Sql Server, Sql Server Error, Sql Server Join, SQLCLR, Stored Procedure, Transact-SQL, Trigger, UNION, UNION ALL, Update with Join | Leave a Comment »

SQL Server / T-SQL

Posted by esersahin on 20/03/2009


http://www.java2s.com/Code/SQLServer/CatalogSQLServer.htm

Posted in Cast, Cross-Tabs, CTE, Functions, Pivot Tables, SQL, Sql Server, Sql Server Error, Sql Server Join, Stored Procedure, Transact-SQL, Trigger | Leave a Comment »

CAST and CONVERT (Transact-SQL)

Posted by esersahin on 13/03/2009


http://msdn.microsoft.com/en-us/library/ms187928(SQL.90).aspx

Posted in Cast, Convert, Transact-SQL | Leave a Comment »

Convert DateTime

Posted by esersahin on 13/03/2009


CREATE PROCEDURE sproc_UpdateTemp_Sub
(
@PreviousDay datetime,
@PresentDay datetime
)
AS

select * from table1 where date between @previousday and @presentday

Go

CREATE PROCEDURE sproc_UpdateTemp
AS

DECLARE @PreviousDay datetime
DECLARE @PresentDay datetime

select @PresentDay = convert( datetime, convert( varchar(10), getdate(), 101 ))
select @PreviousDay = dateadd( day, -1, @PresentDay )

exec sproc_UpdateTemp_Sub @PreviousDay, @PresentDay

Go

Declare @presentday as varchar(10)
SET @PresentDay =  convert( varchar(10), getdate(), 101 )
select * from table where Convert( varchar(10), date1, 101)  = @presentday

Why are you using varchar instead of datetime datatype? If it is just to lose the time part of GetDate it is much more efficient convert it using a float.

Something like

select cast(floor(convert( float,getdate())) as datetime)

returns you today’s date with the time part set to 00:00:00.

You could create a UDT like this:

create function dbo.fnDateFromDateTime(@da

tetime datetime)
returns datetime
AS
begin
return cast(floor(convert( float,@datetime)) as datetime)
end

And call it like this:

select dbo.fnDateFromDateTime(GetDate())

Posted in Cast, Convert, DateTime, SQL, Sql Server, Transact-SQL | Leave a Comment »