Microsoft.WindowsLive.PublishPlugins.dll

For a Codeplex-Example I needed the Microsoft.WindowsLive.PublishPlugins.dll

I could not find this DLL in the Windows Live SDK and read that you can install the Windows Live Messenger 2009.

I downloaded the Setup but it did not work on my development Machine: Windows Server 2003

When I tried to install the new Windows Live Messenger 2009 on my Windows Server 2003 machine, I got the “Couldn’t install programs” error message, and the detail is “os_check: 0×8028004″.

Then I found: Installing Windows Live Messenger 2009 on Windows Server 2003

Thanks to DevaDraco!

As a mirror I post his Solution here:

Apparently, Windows 2003/2008 and 64bit XP systems are not supported by the new Live Messenger.

Thank goodness I came across the following site:
http://www.gtalkme.com/development/install-windows-live-wave3-on-windows2003-or-2008.html
It’s about “Windows Live Wave 3″ and it’s in Chinese, but the hack is identical.

  1. Download the messenger wlsetup-custom.exe.
  2. Open it with Resource Hacker.
  3. Open the resource tree to “CONFIG -> CONFIG0 -> 0″.
  4. Find the XML tag: <os productType=”workstation” />
  5. Change “workstation” to “server” and recompile the script in the Resource Hacker.
  6. Remember to save the modified installer file.

The installer should work properly on the Win2003 system now.

C:\Programme\Windows Live\Photo Gallery\Microsoft.WindowsLive.PublishPlugins.dll

Leave a Comment

Save Result of dynamic SQL-Query in Variable , sp_executesql and OUTPUT

DECLARE @SQLString nvarchar(1000),
	@ParamDef nvarchar(1000),
	@rtnVal nvarchar(1000)

SELECT @SQLString = 'SELECT @rtnVal = convert(varchar,au_id) From pubs.dbo.authors Where au_lname=''Blotchet-Halls'''
Select @ParamDef = '@rtnVal nvarchar(1000) OUTPUT'

EXEC dbo.sp_executesql @SQLString, @ParamDef, @rtnVal OUTPUT 

Select @rtnVal

Leave a Comment

T-SQL: Find Last Day of Month / First Day of Month

http://blog.sqlauthority.com/2007/08/18/sql-server-find-last-day-of-any-month-current-previous-next/

SQL SERVER – Query to Find First and Last Day of Current Month

May 13, 2007 by pinaldave

Following query will run respective to today’s date. It will return Last Day of Previous Month, First Day of Current Month, Today, Last Day of Previous Month and First Day of Next Month respective to current month.

DECLARE @mydate DATETIME
SELECT @mydate = GETDATE()
SELECT CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(@mydate)),@mydate),101) ,
'Last Day of Previous Month'
UNION
SELECT CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(@mydate)-1),@mydate),101) AS Date_Value,
'First Day of Current Month' AS Date_Type
UNION
SELECT CONVERT(VARCHAR(25),@mydate,101) AS Date_Value, 'Today' AS Date_Type
UNION
SELECT CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(DATEADD(mm,1,@mydate))),DATEADD(mm,1,@mydate)),101) ,
'Last Day of Current Month'
UNION
SELECT CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(DATEADD(mm,1,@mydate))-1),DATEADD(mm,1,@mydate)),101) ,
'First Day of Next Month'
GO

Reference : Pinal Dave (http://blog.SQLAuthority.com) , This was requested by my co-worker.

Following script demonstrates the script to find last day of previous, current and next month.
----Last Day of Previous Month
SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE()),0))
LastDay_PreviousMonth
----Last Day of Current Month
SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+1,0))
LastDay_CurrentMonth
----Last Day of Next Month
SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+2,0))
LastDay_NextMonth

ResultSet:
LastDay_PreviousMonth
———————–
2007-07-31 23:59:59.000

LastDay_CurrentMonth
———————–
2007-08-31 23:59:59.000

LastDay_NextMonth
———————–
2007-09-30 23:59:59.000

If you want to find last day of month of any day specified use following script.
--Last Day of Any Month and Year
DECLARE @dtDate DATETIME
SET @dtDate = '8/18/2007'
SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,@dtDate)+1,0))
LastDay_AnyMonth

ResultSet:
LastDay_AnyMonth
———————–
2007-08-31 23:59:59.000

Reference : Pinal Dave (http://blog.SQLAuthority.com)

———————

So many ways to calculate dates….
within the context of the SP, how about only one select statement to give you both first and last?
need to change @FL to 0 = First day and 1 = Last day

DECLARE @FL INT, @d AS DATETIME
SET @d = ISNULL(@d,GETDATE())
SET @FL = 0     -- First day of the month
SELECT DATEADD(mm, @FL + DATEDIFF(mm, 0, @d), 0) - @FL
SET @FL = 1     -- Last day of the month
SELECT DATEADD(mm, @FL + DATEDIFF(mm, 0, @d), 0) - @FL

Leave a Comment

Unable to write output file ‘…pdb’; unspecified error

http://forums.asp.net/t/1360288.aspx
Problem: Unable to write output file ‘…pdb’; unspecified error

Solution: Somebody checked in a .vproj with a file reference and you dont have this file on your machine. Get the file from the others guys computer or make him check in the missing file.

—-

I know this is an old post but I didn’t see an answer for the question itself other than the issue resolving itself.  Hopefully my response will help someone in the future.

I find that this issue tends to come up when users have some type of source control plug in with Visual Studios.  There might be a file that is linked in the vsproj file that is physically missing in the project directory (physically in your inetpub or whatever directory you keep your project in).

What you can do is either get the file and put it in your project directory, or remove the reference to the file in the vsproj file.  The building/rebuilding of the solution might be labelled as “dependent” on the file thus failing to rebuild.

To prevent this in the future, make sure developers are not committing their vsproj files into source control without having committed their new file.  I’m going to guess that the user above updated his/her solution again and received the missing file thus being able to build again.

Yes, I think that is probably the heart of the problem.  The integration between Visual Studio and Visual Source Safe is very poorly thought out.  Generated files should never be included in the source control, but all too often they get pulled in without the user being aware of it.  the problem is not so much not checking  in project files as it is source safe grabbing generated files.  There is no possible reason why a pdb file should be saved in source control…

Leave a Comment

SQL 2005 Management Studio Timeout expired

PROBLEM:

I get the message – “Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding” – when working with large tables in Management Studio.

I have tried changeing the following:

1) Selected Tools -> Options

2) Expanded the “Query Execution” node

3) Clicked on “SQL Server”

4) Set value for “Execution time-out”  to 0 and  various  numbers up to 1800

Also checked the following

1) In Object Explorer I right-clicked on the server and selected “Properties”

2) Selected the “Advanced” page

4) Set the value for “Query Wait” under “Parallelism”  to various values from the default of -1 up to 1800.

I also stopped and restarted SQL after each change.

None of the above changed the fact that the query stopped with the error mesage after about 30 seconds.

SOLUTION:

In the Management Studio, from the Tools menu, select Options, then click “Designers”. There is an option called “Override connection string time-out value for table designer updates:”  In the “Transaction time-out after:” box, you will see the magic 30 seconds.

Source:

http://social.msdn.microsoft.com/forums/en-US/sqltools/thread/e5c0af6e-763e-460b-818b-0e9df6572f12/

Leave a Comment

Select Top 1000 Rows / Edit Top 200 Rows

Why can I only select the top 1000 rows or edit the top 200 rows in the sql server 2008 management studio?
I hated this feature but gave in to my fate that I could not change it – It did not come to my mind that you can change it at all. I thought: “That is an evil Microsoft feature.”

Behold! Because you can change your fate (at least this time!):

Go to Tools –> Options –> SQL Server Object Explorer and you can change the table and view options.

Enter Zero to Edit or Select ALL Rows!

Value for Edit Top <n> Rows command
Value for Select Top <n> Rows command

Leave a Comment

ATC Simulator’s (Flash) from bigfatsimulations.com

In the past I loved playing FS2004 and ATCsimulator®2. Flying is very time consuming so I quit. Today I found some nice ATC Flash-Games you might enjoy. I love organizing those little Planes just in Time. :-)

Here are two games you can also find on BigFatSimulations.com

Leave a Comment

The ultimate guide to the datetime datatypes

I am mirroring the blog entry from Tibor Karaszi for my use in case the articel gehts lost (don’t you love the 404?)


Updated for SQL Server 2008

Overview

The purpose of this article is to explain how the datetime types work in SQL Server, including common pitfalls and general recommendations.

Thanks to SQL Server MVP Frank Kalis,
this article is translated to German.

Acknowledgements

I like to thank the following persons who provided valuable suggestions and input for this article: Steve Kass,
Aaron Bertrand, Jacco Schalkwijk, Klaus Oberdalhoff, Hugo Kornelis, Dan Guzman and Erland Sommarskog.

Versions of SQL Server

This article applies to SQL Server 7.0, 2000, 2005 and 2008, where not noted otherwise.


Contents

Date and time types in SQL Server

Date and time formats

Date and time formats for input

Recommendations for input

Warnings and common misconceptions

Output of datetime values

Searching for datetime values

Getting rid of the time portion

Tip: Always set the time to the same value

Other tips, from SQL Server MVP Steve Kass

Why is 1753 the earliest date for datetime?

References and reading tips

Date and time types in SQL Server

Prior to SQL Server 2008, there are two types in SQL Server to handle date and time.
Since I will be referring to these types a lot, I introduce an abbreviation for each type in below two tables (the “sn” column):

Name sn Minimum value Maximum value Accuracy Storage
smalldatetime sdt 1900-01-01 00:00:00 2079-06-06 23:59:00 minute 4 bytes
datetime dt 1753-01-01 00:00:00.000 9999-12-31 23:59:59.997 3.33 ms 8 bytes

Note that there is no type to store only date or only time. Above types have both a date and a time portion.

If you only specify a date portion, then SQL Server will store 00:00:00.000 in the time portion.

And if you only specify a time portion, SQL Server will store 1900-01-01 in the date portion.

Above is important. Read it again.

SELECT CAST('20041223' AS datetime)


-----------------------

2004-12-23 00:00:00.000
SELECT CAST('14:23:58' AS datetime)

-----------------------

1900-01-01 14:23:58.000

As of SQL Server 2008, we have several new types related to date and time:

Name sn Minimum value Maximum value Accuracy Storage
datetime2 dt2 0001-01-01 00:00:00.0000000 9999-12-31 23:59:59.9999999 100ns 6-8 bytes
date d 0001-01-01 9999-12-31 day 3 bytes
time t 00:00:00.0000000 23:59:59.9999999 100ns 3-5 bytes
datetimeoffset dto 0001-01-01 00:00:00.0000000 9999-12-31 23:59:59.9999999 100ns 8-10 bytes
  • As you can see, we have finally a date-only and a time-only type.
  • Datetime2 is a “better datetime” for various reasons, and it doesn’t cost any more storage than datetime – potentially less!
  • For the new types which includes a time portion, you can specify a “fractional seconds precision” part which specifies how many digits you have to the right of the comma after the second.
    So, for instance time(3) can store a value like 14:23:12.567, where if you input 14:23:12.5677 it will be rounded to 14:23:12.568.
  • The new datetimeoffset includes a time zone offset part.

Date and time formats

A common misconception is that SQL Server stores these datatypes in some particular readable format. That is not the case.
SQL Server stores these values in an internal format (for instance two integers for datetime and smalldatetime).
However, when you use T-SQL to specify a value (in an INSERT statement, for instance) you express it as a string.
And there are rules for how different datetime string formats are interpreted by SQL Server. But note that SQL Server does not remember the format in any way.

Date and time formats for input

There are many formats available for ut to specify a date/time/datetime value.
Some are “better” than others and as you read further through this article I hope you will understand what I mean by “better”. Interestingly enough, all formats are available for all types.
So even a time-only format is allowed for a date-only type etc.

(I’m ignoring the time zone offset part which is only used for the datetimeoffset type – you can read more about this in Books Online.)

Name sn Format SET DATEFORMAT dependent SET LANGUAGE dependent language neutral
Unseparated u ‘19980223 14:23:05′ none none all
Separated s ‘02/23/1998 14:23:05′ all all no
ANSI SQL ansisql ‘1998-12-23 14:23:05′ sdt, dt sdt, dt not for sdt and dt
Alphabetic a ‘23 February 1998 14:23:05′ none all (month name) no
ODBC datetime odt {ts ‘1998-02-23 14:23:05′} none none all
ODBC date od {d ‘1998-02-23′} none none all
ODBC time ot {t ‘14:23:05′} none none all
ISO 8601 iso ‘1998-02-23T14:23:05′ none none all
Time t ‘14:23:05′
‘2:23:05 PM’
none none all
  • Note that ANSI SQL is really only a special case of the separated (aka “numeric”) format, which allow for separators dash (-), slash (/) and dot (.).
    But since this is the only format defined in the ANSI SQL standard, I think it is worth mentioning this as a special case.
  • Most formats allow for dropping the date and/or the time portion, and in some cases it can look a bit … strange.
    It might seem stupid to specify for instance ‘2008-08-25′ for a time type, but doing that result in same as specifying nothing in the datetime string, ”.
    Consider below:

    SELECT CAST('' AS time)

    SELECT CAST(‘2008-08-25′ AS time)

    Above two gives us the same result (time 00:00:00).

  • The ODBC formats are different in the sense that they have a marker (literal_type, t, d or ts), you need to define correctly depending on whether you specify both date and time,
    date only or time only.
  • The ISO 8601 format requires both a date and a time portion.
  • SET DATEFORMAT inherits its setting from SET LANGUAGE (but an explicit SET DATEFORMAT will override later SET LANGUAGE). The language defaults to each login’s language.
    Default language for a login is specified using sp_configure.
  • The rules regarding the format for the date part and the new types can be confusing.
    Microsoft wanted to make the new date related types (date, datetime2 and datetimeoffset) less dependent on these settings and also more ANSI SQL compliant.
    End result is that these new types are language neutral for a separated datetime literal as long as the year comes first.
    SQL Server need to determine that this is the year part, so it requires 4 numbers year (yyyy, not yy).
    If that is the case, then the string will be interpreted as year first, then month and finally day – regardless of DATEFORMAT or language setting.
    But if the month part comes first, then DATEFORMAT and language setting will be “honored”:

    SET LANGUAGE British --uses dmy

    GO

    SELECT CAST(‘02-23-1998 14:23:05′ AS date) –Error

    GO

    SELECT CAST(‘2/23/1998 14:23:05′ AS date) –Error

    GO

    SELECT CAST(‘1998-02-23 14:23:05′ AS date) –Ok

    GO

    SELECT CAST(‘1998.02.23 14:23:05′ AS date) –Ok

    GO

    SELECT CAST(‘1998/02/23 14:23:05′ AS date) –Ok

    GO
    The first two fails because the year doesn’t come first (and there are not 23 months in 1998). The last three doesn’t fail because the year comes first (and we are using one of the new style date related types).

    Crystal clear, huh? :-)

The available formats are documented in Books Online, so I won’t go into details about each format.
Here’s a link to the online version of Books Online,
see each subsection for the different formats.

Note that the ODBC time only format will give the current date, not 1900-01-01 as the other time-only formats.

Some conclusions:

  • The Alphabetic format is especially bad since this is SET LANGUAGE dependent for all types.
  • The smalldatetime and datetime types are unfortunate since they are dependent on not only SET LANGUAGE but also SET DATEFORMAT (including the login’s language setting).
  • You might think that it doesn’t matter if a format/type combination is SET LANGUAGE dependent or not since “I never execute that SET LANGUAGE command anyhow”.
    But note very carefully that the default for DATEFORMAT is drawn from the login specification (CREATE LOGIN etc.).
    Imagine for instance an app developed in the US with login having default language (us_english) using m/d/y format and datetime.
    Somebody in, say, Germany installs it and bang! The app doesn’t work anymore. Do I have your attention now? :-)
  • The types introduced in 2008 are friendlier since they are not SET DATEFORMAT dependent if you
    for a separated format specify the year first.
    For the separated formats (including ANSI SQL), the new types always interprets month before date.

Recommendations for input

As you probably realize, you don’t want to use a combination of format and type which isn’t language neutral unless you
make sure that you have the correct DATEFORMAT and LANGUAGE settings in your applications.
Be aware that setting these options inside a stored procedure can cause a recompile of the procedure at execution time!

My recommendation is to use a language neutral format. I typically use the unseparated format, mostly out of old habit.
The ISO 8601 format has the advantage of being defined in an international standard.

SQL Server 2008 has just been released at the time of writing this, but I will probably move towards date, time, datetime2 and possibly datetimeoffset over time.
Over time, I might be using the ANSI SQL format (being ANSI SQL compliant) with the new types, but i’d rather that ANSI SQL supports the ISO 8601 format.
I will play it safe and use unseparated or ISO 8601 for a number of years to come – even when working with the new types.

Warnings and common misconceptions

Let me say this again: you don’t want to use a combination of format and type which isn’t language neutral unless you make sure that you have the correct DATEFORMAT and LANGUAGE settings in your
applications.

The Numeric format can use dash (-), dot (.) or slash (/) as separator. The rules for how SQL Server parses the string doesn’t change depending on the separator.
A common misconception is that the ANSI SQL format (sometime a bit incorrectly referred to as the “ISO format”), 1998-02-23, is language neutral for smalldatetime and datetime. It isn’t.
It is a numeric format and hence it is dependent on the SET DATEFORMAT and SET LANGUAGE setting:

SET LANGUAGE us_english

SELECT CAST(‘2003-02-28′ AS datetime)

———————–

2003-02-28 00:00:00.000

SET LANGUAGE british

SELECT CAST(‘2003-02-28′ AS datetime)

Server: Msg 242, Level 16, State 3, Line 4

The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.

Please read the error message closely. It says exactly what the problem is. You specify the datetime value as a string,
and because the string isn’t formed according to the format you are using and the DATEFORMAT setting, SQL Server cannot convert the string to a datetime value.

Output of datetime values

When a datetime value leaves SQL Server is has no readable format. It is the client application that formats the value so it is human-readable.
Some applications/developer environments will respect the regional settings of the client machine and format the value accordingly. But this is out of SQL Server’s control.
You can return the data from SQL Server using a specific format, but that requires you to convert it to a string, and the value will not be of the datetime type anymore.
If you want to do this, use the CONVERT function, which has a useful 3:rd parameter that defines the format when you convert from datetime to a string. A few examples:

SELECT CONVERT(char(8), CURRENT_TIMESTAMP, 112)

--------

20040312

SELECT CONVERT(char(19), CURRENT_TIMESTAMP, 120)

-------------------

2004-03-12 18:08:43

SELECT CONVERT(char(10), CURRENT_TIMESTAMP, 103)

----------

12/03/2004

Searching for datetime values

The problem with datetime searches often comes from the fact that if you use smalldatetime, datetime, datetime2 or datetimeoffset then there is both a date and a time portion.
Let’s create table that we will use in a couple of examples:

CREATE TABLE #dts(c1 char(1), dt datetime)

INSERT INTO #dts (c1, dt) VALUES(‘a’, ‘20040305 09:12:59′)

INSERT INTO #dts (c1, dt) VALUES(‘b’, ‘20040305 16:03:12′)

INSERT INTO #dts (c1, dt) VALUES(‘c’, ‘20040306 00:00:00′)

INSERT INTO #dts (c1, dt) VALUES(‘d’, ‘20040306 02:41:32′)

INSERT INTO #dts (c1, dt) VALUES(‘e’, ‘20040315 11:45:17′)

INSERT INTO #dts (c1, dt) VALUES(‘f’, ‘20040412 09:12:59′)

INSERT INTO #dts (c1, dt) VALUES(‘g’, ‘20040523 11:43:25′)

Say that we want to find all rows from 2004-03-15. A common mistake is to search like this:

SELECT c1, dt FROM #dts WHERE dt = '20040305'

No rows returned. Why? What happened? We have two different types in the WHERE clause, a datetime type (the column side) and a string (the right side).
SQL Server will convert one to the other according to the documented “Data Type Precedence” in Books Online.
Datetime has higher precedence than a string so the string will first be converted to a datetime type. As we didn’t specify a time portion, the string will be converted to the
datetime value 2004-03-05 00:00:00. There are no rows with that datetime value.

OK, another alternative. We use the CONVERT function on the column side and convert it to a string so it matches the string format on the right side:

SELECT c1, dt FROM #dts WHERE CONVERT(char(8), dt, 112) = '20040305'

That returned the expected rows, but there’s another problem. Since we do a calculation on the column side (using the CONVERT function),
SQL Server cannot use an index to support this search criteria. This can be disastrous for performance! So let’s try BETWEEN:

SELECT c1, dt FROM #dts WHERE dt BETWEEN '20040305' AND '20040306'

Because BETWEEN is inclusive, we also returned the row from 2004-03-06 00:00:00. Let’s try to handle that:

SELECT c1, dt FROM #dts WHERE dt BETWEEN '20040305' AND '20040305 23:59:59.999'

What? We still got the row from 2004-03-06 00:00:00 back. Why? We need to look at the type definitions again. The resolution for the datetime type is 3.33 ms.
That means that 2004-03-05 23:59:59.999 will be rounded up to 2004-03-06 00:00:00.000. Not what we expected. To get around that rounding problem, we try:

SELECT c1, dt FROM #dts WHERE dt BETWEEN '20040305' AND '20040305 23:59:59.997'

Above return the expected rows, but I would not call it intuitive and easy to read.
Also, if the type in the table is smalldatetime instead of datetime, the time portion will again be rounded up, hence not producing the expected rows. So you find yourself having two
ways of doing this dependent on whether you have datetime or smalldatetime. If the type is smalldatetime, you would use:

SELECT c1, dt FROM #dts WHERE dt BETWEEN '20040305' AND '20040305 23:59:00'

Having two different ways of doing this depending on the datatype is not something I recommend.
And, who knows if Microsoft in the future will add types with higher precision for the time portion (which they did in SQL Server 2008)? Again you would have to adjust the time portion in the WHERE clause.
Below you find my recommendation:

SELECT c1, dt FROM #dts WHERE dt >= '20040305' AND dt < '20040306'

We get the expected rows back and it is easy to understand what the criteria means. And SQL Server can use an index on the dt column.
This is also easy to expand for searches on greater ranges. Say we want to return all rows for March 2004:

SELECT c1, dt FROM #dts WHERE dt >= '20040301' AND dt < '20040401'

Same logic. Here’s another way to search for all rows from a specific month:

SELECT c1, dt FROM #dts WHERE DATEPART(year, dt) = 2004 AND DATENAME(month, dt) = 'March'

Above returns the expected rows, but there are two problems. Since there is a calculation on the datetime column, SQL Server cannot use an index on the dt column to support the query.
And, the DATENAME function is dependent on SET LANGUAGE.

Getting rid of the time portion

It is very common that you only want to work with date, and you want to get rid of the time portion. As you should know by now it is impossible if you
are a using smalldatetime, datetime, datetime2 or datetimeoffset type. If you are using date, then no problem – this is what date is for, after all!
But if you insist for some reason to use smalldatetime, datetime, datetime2 or datetimeoffset then perhaps setting the time portion to 00:00:00 is fine for you?
Here’s my suggestion for an expression that returns a string that can be (implicitly) converted to a datetime value, regardless of SET LANGUAGE or DATEFORMAT:

CONVERT(char(8), CURRENT_TIMESTAMP, 112)

As you see, I use CONVERT with conversion code 112, which return the date in unseparated format, as a string. And you already know that the unseparated format is interpreted regardless
of datetime or language settings when converted to datetime. Let us wrap above in a CAST to convert it to datetime:

SELECT CAST(CONVERT(char(8), CURRENT_TIMESTAMP, 112) AS datetime)

In case you truly only want to return the date and no time portion to the client application, then you have to return a string instead (or as of 2008, the date type).
Again, read about the different conversion codes for the CONVERT function and you will probably find a format which suits you.

Hugo Kornelis had some feedback on this topic and suggests another technique for setting the time portion to 00:00:00.
The idea is to decide on a base date (any date within SQL Server’s datetime range will do), specify it so that time portion is 00:00:00.
You first take the difference between today and this base date, in days.
Then you add this number of days to the base date. Algorithm: [today]-[refdate]+[refdate], or expressed with TSQL (using 20040101 as base date):

SELECT DATEADD(day, DATEDIFF(day, '20040101', CURRENT_TIMESTAMP), '20040101')

An argument for above is that is is faster than doing string manipulations.
My opinion has been that the difference is so small (a few microseconds according to tests I did about year 2000) so that this would probably not even be measurable.
However SQL Server MVP Dan Guzman emailed me with some to me surprising information. Here’s a quote from the email:

“I’ve found that the DATEADD technique significantly outperforms the string
method when the expression is applied to a column in large queries. For
example, I often use the DATEADD method to group by date when the datetime
column includes a time component. I haven’t tested the performance recently
but I recall it was minutes in some
cases.”

Dan is someone I trust very much, so I guess I have some re-learning to do
(start using the DATEADD method instead of the string method). Dan also followed up with a script file showing this.
Here it is (with some minor formatting modifications made by me).
My tests show consistent results on 2005 and 2008 where for 10,000,000 rows the DATEADD version took about 6 seconds and the string version took about 13 seconds.
Dan reported even greater difference on 2000.

2009-04-03, I received an email from Håkan Borneland. He mentioned that is is common, for instance in the MSDN forums, to use first alternative below, instead of second
alternative (which I had originally in my performance test script):

SELECT DATEADD(DAY, 0, DATEDIFF(DAY, 0, CURRENT_TIMESTAMP))

SELECT DATEADD(DAY, 0, DATEDIFF(DAY, , CURRENT_TIMESTAMP))

Note that both these differs from the DATEDIFF version discussed slightly higher above. So now we have 4 different ways to accomplish this.
“My” original string manipulation method and three DATEDIFF alternatives:

SELECT CAST(CONVERT(CHAR(8), CURRENT_TIMESTAMP, 112) AS datetime) --1

SELECT DATEADD(DAY, 0, DATEDIFF(DAY, , CURRENT_TIMESTAMP)) –2

SELECT DATEADD(DAY, DATEDIFF(DAY, ‘20040101′, CURRENT_TIMESTAMP), ‘20040101′) –3

SELECT DATEADD(DAY, 0, DATEDIFF(DAY, 0, CURRENT_TIMESTAMP)) –4

If you feel that you do operations so that performance can be a major concern, then I suggest you
test. Here is an updated performance test script, with all four versions.
Alternative 1 is slowest and the three DATEDIFF alternatives (2-4) are pretty close with alternative 4 as the winner.
I also suggest you consider readability, which can be a matter of oppinion.

The DATEADD alternative also has the advantage of flexibility. Instead of re-typing the suggestions from Hugo,
I’ve just copied the original text from Hugo in the email he sent to me:

The version that uses string conversion can only be used to strip the time from the date.
The dateadd/datediff version can easily be varied to get the start of the current month, quarter or year.
SELECT DATEADD(month, DATEDIFF(month, ‘20000101′, CURRENT_TIMESTAMP), ‘20000101′)
Or to discard only minutes and seconds, or only seconds
SELECT DATEADD(hour, DATEDIFF(hour, ‘20000101′, CURRENT_TIMESTAMP), ‘20000101′)
(Note – when dealing with minutes, seconds or milliseconds, the DATEDIFF function CAN overflow the integer range – the date constant might
have to be adapted to the expected set of datetime values).

Further variations are also possible: How to get the last day of the previous month? And the last day of the current month?

SELECT DATEADD(month, DATEDIFF(month, '20000101', CURRENT_TIMESTAMP), '19991231')

SELECT DATEADD(month, DATEDIFF(month, ‘20000101′, CURRENT_TIMESTAMP), ‘20000131′)

How to get tomorrow’s date (without time)?

SELECT DATEADD(day, DATEDIFF(day, '20000101', CURRENT_TIMESTAMP), '20000102')

How to round the datetime to the nearest hour, or to the nearest day?

SELECT DATEADD(hour, DATEDIFF(hour, '20000101', DATEADD(minute, 30, CURRENT_TIMESTAMP)), '20000101')

SELECT DATEADD(day, DATEDIFF(day, ‘20000101′, DATEADD(hour, 12, CURRENT_TIMESTAMP)), ‘20000101′)

How to get last Friday’s date, without using a calendar table and regardless of the current DATEFIRST setting?

SELECT DATEADD(day, (DATEDIFF (day, '20000107', CURRENT_TIMESTAMP) / 7) * 7, '20000107')

or

SELECT DATEADD(day, (DATEDIFF (day, '20000108', CURRENT_TIMESTAMP) / 7) * 7, '20000107')

The first will return the current day if run on friday, the latter will return the previous friday.

Once you understand the general principle, it isn’t hard to come up with new variations, that might be useful in specific circumstances.

Tip: Always set the time to the same value

If you aren’t interested in the time portion and you can’t use the date type, you can set the time portion to a standard value for all rows. I recommend 00:00:00.000.
Say you want to set the value to the current date when the INSERT is performed. For that you can use a DEFAULT constraint:

CREATE TABLE #dts(id INT IDENTITY, d_date DATETIME DEFAULT CONVERT(char(8), CURRENT_TIMESTAMP, 112))

INSERT #dts DEFAULT VALUES

SELECT * FROM #dts

I’m using the code 112 in the CONVERT() function above, which returns a string with the date only, in the unseparated format.
However, we have not protected us from if anyone now explicitly sets the value and set the time portion to something other than 00:00:00:000. We can do that with a constraint:

ALTER TABLE #dts ADD CONSTRAINT dts_chk_d_date CHECK(CONVERT(char(12), d_date, 114) = '00:00:00:000')

What advantage does above give us? If we now want to search for all rows from a certain date, we can write the WHERE clause like:

WHERE dt = '20040305'

Above might be considered easier to read and understand. Also, say you want to join between two table based on the day only, you can now do this directly. If you have a time portion
that varies, you would have to use some CONVERT in the JOIN operation which again can be disastrous for performance.

Above technique can also be applied if you are only interested in the time portion, in that case I recommend that you always set the date portion to 1900-01-01.

Now, isn’t it great that we as of 2008 have separate data and time types?

Other tips, from SQL Server MVP Steve Kass

The super-careful can specify all dates in queries as smalldatetime, using cast or convert. But note that this may have unexpected behavior
in SQL Server 7.0 against a (not small-) datetime column.

Without a very good reason and comments everywhere, store dates only as datetime or smalldatetime, and not as strings. If dates must be stored
as strings (there are some good reasons to, but they are few), use a language neutral format and a 24-hour clock if time is also stored, so
that the strings work everywhere and also sort the way the dates sort. For example, you use “dt < ‘20030101′” in the WHERE clause and the query doesn’t return expected rows because dt is
stored as a string in yyyy-mm-dd format.

The base date in Enterprise Manager (and some other Microsoft tools and applications) is 1899-12-30. EM should never be used for data entry,
and rarely if ever for viewing data. If you use EM to specify time-only data, EM will store the date 1899-12-30. If you really want to use EM, specify the date 1900-01-01 explicitly.
Note also that EM will only show the time portion if the date is 1899-12-30, not what you expect if you use 1900-01-01 as a standard value for date.

Why is 1753 the earliest date for datetime?

Good question. It is for historical reasons. In what we sometimes refer to as the western world, we have had two calendars in modern time: the Julian and the Gregorian calendars.
These calendars were a number of days apart (depending on which century you look at),
so when a culture that used the Julian calendar moved to the Gregorian calendar, they dropped from 10 to 13 days.
Great Britain made this shift in 1752 (1752-09-02 were followed by 1752-09-14). An educated guess why Sybase selected 1753 as earliest date is that if you were to store
an earlier date than 1753, you would also have to know which country and also handle this 10-13 day jump. So they decided to not allow dates earlier than 1753.
Note, however that other countries did the shift later than 1752.
Turkey, for instance, did it as late as 1927.

Being Swedish, I find it a bit amusing that Sweden had the weirdest implementation. They decided to skip the leap day over a period of 40 years (from 1700 to 1740),
and Sweden would be in sync with the Gregorian calendar after 1740 (but meanwhile not in sync with anyone).
However, in 1704 and 1708 the leap day wasn’t skipped for some reason, so in 1712 which was a leap year, they inserted yet an extra day (imagine being born in Feb 30!)
and then did the shift over a day like everyone else, in 1753.

References and reading tips

This is by far the most elaborate document I’ve found about calendars:

Frequently Asked Questions about Calendars, by Claus Tøndering

The book “Developing time-oriented database applications in SQL” by Richard T. Snodgrass contains a lot of information about how you can represent time-oriented information
in a data model. And, of course, how you can utilize this extra (historical) information in your SQL queries. This book is out of print,
but on Rick’s homepage (www.cs.arizona.edu/people/rts), you can download the pdf for free.

Leave a Comment

In US Army what are S1 S2 S3 and S4?

S1-4 in the US Army deal with specific duties; these are:

S-1, Personnel: processes awards, solves problems with pay, requests new troops for assignment, and addresses issues under UCMJ (Uniform Code of Military Justice).

S-2, Intelligence: collects data on enemy movement, strengths, and battlefield deployments, and makes recommendations for command. The S-2 office also handles security clearances, maintains the battalion/brigade’s Signal Operating Instructions and radio codes, and usually maintain’s the battalion’s map collection.
[Map Reading]

S-3, Trainng and Operations: S3 has different missions in war and peace times. During peacetime, S3 schedules and monitors training within the unit and for subordinate units. For tactical operations, S3 plans all movements and deployments. S-3 is also responsible for ammunition supply.

S-4, Supply: As implied by the name, Supply is the clearing house for all military materials. They handle requests for new supplies and replacement equipment, keep unit property books, and plan logistical movement of equipment. S-4 has no responsibility for ammunition supply.

Leave a Comment

How to save flash movies in Firefox

Mozilla Firefox has built-in features to save Flash movies. When viewing a web page:

  1. Right-click on the web page;
  2. Select View Page Info;
  3. Switch to the “Media” tab;
  4. Select the Flash movie you want to save;
  5. Click Save As.

Leave a Comment

Set SPFieldDateTime DefaultValue in WSS 2.0

PROBLEM:
How to set the DefaultValue of a SPFieldDateTime?

SOLUTION:
Dim DateField As SPFieldDateTime
DateField.DefaultValue = “2012-05-19T00:00:00Z

REMARK:
In Wss 3.0 you have the SPUtility.CreateISO8601DateTimeFromSystemDateTime Method (Microsoft.SharePoint.Utilities)
to help you out

Leave a Comment

Name cannot begin with the ‘0′ character

PROBLEM:
Working with a WSS 2.0 List I get this Exception when adding the formula:
System.Xml.XmlException: Name cannot begin with the '0' character, hexadecimal
value 0x30. Line 1, position 170.
 at System.Xml.XmlTextReaderImpl.Throw(Exception e)
Here a part of the code:
Dim DelayField As SPFieldCalculated = SP_Web.Lists(TimeList).Fields(Delay)
DelayField.Formula = "=INT([Column X]<0;2;0)"
DelayField.DisplayFormat = SPNumberFormatTypes.NoDecimal
DelayField.Update()
SOLUTION:
The Formula is a String but in Sharepoint it is read as XML. So the <0 is the Problem.
Changing the <0 to lt;0 write the formula like this:

DelayField.Formula = "=INT([Column X]lt;0;2;0)"

Leave a Comment

Check if a database or table exists using Sql Server 2005

Check if a database or table exists using Sql Server 2005

The Object_ID() function in SQL Server can be utilised in a number of ways. One such utility is to verify if an object exists.

The Object_ID() takes in the object name and object type as parameters. The object name is the object used and the object type is the type of object used in a schema.

For example to check if a table exists in a database, use this query :

IF OBJECT_ID (‘AdventureWorks.dbo.AWBuildVersion’,'U’) IS NOT NULL
Print ‘Table Exists’
ELSE
Print ‘Table Does Not Exists’

where ‘AdventureWorks.dbo.AWBuildVersion’ is the object name and ‘U’ is the object type which represents a table

Similarly you can check for a stored procedure or a view by specifying the correct object type. You can get an entire list of object types over here.

To check if a database exists, you can use the DB_ID() function as shown below :

IF db_id(‘AdventureWorks’) IS NOT NULL
Print ‘Database Exists’
ELSE
Print ‘Database Does Not Exists’

Comments (1)

WordPress, Unicode and ?

http://hansengel.wordpress.com/2007/10/09/wordpress-unicode-and-s/ wrote this:

I previously had some problems when I mixed Unicode with WordPress. Every time I typed a Unicode character, (after posting) it would display as a ‘?’. This post will describe how to fix this.

Basically, the problem is that WordPress is not comprehending this, and instead of telling the database to store the Unicode characters, it just says, “Heck, just stick a bunch of question marks in there.”

Of course, this can be easily fixed in two steps. All you’ll need is FTP access to your server and a fair comprehension of how to type. So, let’s get started!

  1. Open up ‘wp-config.php’ from the root directory of your WordPress installation.
  2. Add ‘//’ at the very beginning of these two lines:
    define('DB_CHARSET', 'utf8');
    define('DB_COLLATE', '');

So that section should now look like this:
//define('DB_CHARSET', 'utf8');
//define('DB_COLLATE', '');

You’re already finished. How easy was that?

Important notes:

  1. The quotes surrounding // in step 2 should not be inserted. Those are just indicating that the // is the part you should insert.
  2. If you’ve meddled with that part of ‘wp-config.php’ before, it may look a bit different. But pay no attention to the differences. Just be sure add // to the lines containing DB_CHARSET and DB_COLLATE.

Leave a Comment

Turkish unicode characters

Found on http://kuysal.blogspot.com/2008/03/turkish-unicode-characters.html

* ? – \u011f
* ? – \u011e
* ? – \u0131
* ? – \u0130
* ö – \u00f6
* Ö – \u00d6
* ü – \u00fc
* Ü – \u00dc
* ? – \u015f
* ? – \u015e
* ç – \u00e7
* Ç – \u00c7

Leave a Comment

Changing the collation of the SQL Server 2005

After an installation of SQL Server 2005 a Software-Setup didn’t run because it demanded a case-insensitive collation. We had Latin1_General_CS_AI and wanted to change to Latin1_General_CI_AI.

This is not a trivial task and can make you a lot of pain, so maybe this helps. Many thanks to Tom Wisnowski.
This is his blog entry from http://geekswithblogs.net/mskoolaid/archive/2005/12/17/63413.aspx :

Step 1. Put SQL Server into Single User Mode

The first thing you will want to do is stop the SQL Sever Sevicer (sqlservr.exe) and the associated services (Agent, Full Text, Etc). There are a few ways to do this, but the easiest way would be to use the SQL Configuration Manager (Start->All Programs->Microsoft Sql Server 2005->Configuration Tools->Sql Server Configuration Manager). From this console you can manage the various SQL server services running on the machine. Right Click on each service listed and stop the service. The services are stopped, you can proceed to Step 2.

Step 2. Start the SQL server in Single User Mode

Open a command window and navigate to the folder where Sqlservr.exe resides (generally :\Program Files\Microsoft Sql Server\MSSQL.1\MSSQL\Binn). Run “sqlserver.exe -m” to start the sql server from single user mode.

Step 3. Rebuild the system databases

In SQL 2005, the rebuildm.exe program is nto supported. To rebuild the master database you need to use the setup.exe found on the SQL 2005 installation media. To rebuild, use the following command “start /wait setup.exe /qn INSTANCENAME= REINSTALL=SQL_Engine REBUILDDATABASE=1 SAPWD=”. Please refere to Books on Line for compelete details on how to use Setup.exe.

Step 4. Restart the SQL Server Services in regular mode

End the command shell you started earlier. Ctrl-C to stop SQL server in single user mode, then close the command window. Go back to the Sql Server Configuration Manager and restart the SQL services.

Setup /QUIET /ACTION=REBUILDDATABASE /INSTANCENAME=InstanceName
/SQLSYSADMINACCOUNTS=accounts /[ SAPWD= StrongPassword ]
/SQLCOLLATION=CollationName

Use /SQLCOLLATION= with the name you need.
For a List of collations use: SELECT * FROM fn_helpcollations()

Latin1_General_
CI = Case Insenstive
CS = Case Senstive
AI = accent-senstive
AS = accent-insensitive and so forth.

Leave a Comment

Create Date from Integers in T-SQL

Thanks to Jeff

declare @y int;
declare @m int;
declare @d int;

– the date we wish to create is Nov 6, 2003:
set @y = 2003
set @m = 11
set @d = 6

select dateadd(mm,(@y-1900)* 12 + @m – 1,0) + (@d-1)

For my site-search: Convert Date, ConvertDate, DateConvert,Int,Integer,IntToDate,IntegerToDate,Datum

Leave a Comment

Import .vob into Adobe Premiere .vbo (<–For missspellers in Google)

Error “File format not supported” when you import VOB files

Issue

When you try to import VOB files into Adobe Premiere Elements 1.0 or Premiere Pro 1.x, the application returns the error message, “File format not supported.”

Solutions

Premiere Elements 1.0 and Premiere Pro 1.x do not support importing and editing the VOB file format. If you must work with the contents of a DVD, the following suggestions may provide you with possible workflows for using this material in Premiere.

Solution 1: Change the .vob file extension to .mpg, and then import into Premiere.

Note: Premiere Elements and Premiere Pro do not import encrypted DVD MPEG files . The technique described below only works when used with VOB files that have not been encrypted.

  1. Open My Computer, right-click the DVD drive, and choose Explore.
  2. Navigate to the Video_TS folder.
  3. Copy the VOB files to your hard drive.
  4. Change the VOB file extensions (.vob) to the MPEG file extension (.mpg).
  5. Import the MPEG files into Premiere Elements 1.0 or Premiere Pro 1.x.
  6. Render the footage on the time line.

Solution 2: Convert the MPEG files to DV AVI

Use a third-party application (such as VirtualDub, DVD2AVI, or Mpeg2AVI) to convert the MPEG files from Solution 1 to Microsoft DV AVI, and then import the DV AVI files into Premiere.

Background information

For additional information on converting VOB files to DV AVI files as well as other format conversion, visit www.videohelp.com .

Leave a Comment

Big-Font in Outlook. Cannot change Font-Size in Outlook!

I thought I was all alone with this Problem. My font in Outlook was so big, even if I hat it in Arial 9!
A co-worker was able to help me out quick. Today I have seen the same problem at another’s co-worker screen and he told me: “I don’t know how to change it back!” … Damn the Mouse-Wheel. :-)

damn_the_wheel

Leave a Comment

Trainer Operation Flashpoint (OFP) 1.96

Operation Flashpoint Cold War Crisis Multiplayer Cheat

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
TKC Supercheatpack 1.21 Final

This cheat is brought to you by TKC

The Teamkilling and Cheating community

Visit us at:   http://www.tkc-community.net

Programmers: [YENG]Hubertus & [TKC]Anothercheater

Thanks to all who helped beta-testing and giving new ideas ;)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~v1.21~

-DISCLAIMER-

This software is provided ‘as-is’, without any express or implied warranty.
You are not allowed to continue the  setup-process if it would result in
breaking legal laws, legal license agreements or patents of any government.
The files included in this release are meant for educational purposes only.
Neither the authors of this file nor the TKC-Community can be held
responsible for any damages this release may cause to you, your grandma
and/or your computer. In fact neither the authors of this file nor the TKC-
Community can be held responsible for anything you  do with the files
contributed in this release, like illegal activities.
USE AT YOUR OWN RISK ONLY! And remember to have fun :)

-INSTALL-
0. Do NOT copy the setup.exe to your OFP folder.
1. Doubleclick the Setup.exe and follow the instructions.
2. Select your existing Operation Flashpoint folder which MUST
contain the FlashpointResistance.exe.
3. Press Continue and your ofp is patched and ready for use.

-FEATURES-

+ Undetectable from any server through a smart patch engine
+ ESP Hack – See where your enemies are
+ Fog Hack – Remove fog and increase the viewdistance
+ Godmode – The easiest way to get unkillable
+ Manipulate Objects & Players (Move, Destroy, Repair, Put in Air, Copy,
Hide, Delete, …)
+ Spawn any Vehicles you want on any map – Choppers, Planes, Tanks,
Papercars, LST…
+ Special Effects – Spaceworld, Delete ALL Objects, Boats, Logos, Bombs,
Parachutes, Crazy CTF Flags, Walk on Water…
+ CTI Tools – Delete the MHQs, Teleport yourself to the enemie MHQ, Switch
the MHQs, Send out drones to the enemy MHQ…
+ SUPERWEAPONS – Get the big ass guns ready and kill the cornercamper
with a Maverick, Sabot, MG, 30mm, Bombs, etc.
+ Free Camera Scripts, Restore Fog, Anonymouse Killing, Flying Trucks,
Guba & Angelina, AI Flooding, Wallstreets, Churches, Towers, …
+ And many more, checkout www.tkc-community.net for more

-STARTUP-

1. Start a multiplayer game
2. After the game started you need to die once so you respawn, after that
you can access the === SUPERCHEATMENU ===.

-ADDITIONAL-

If you got problems running this cheat or for additional cheats (1.96 ID-
Changer, 1.96 Ammotrainer, etc) goto www.tkc-community.net/Forums
and read the existing topics in the OFP section.

Have fun and good luck!

Copyright © 2003-2005 by TKC-Community.net

Download

Leave a Comment