What’s the best way to select the minimum value from several columns?
Using CROSS APPLY: SELECT ID, Col1, Col2, Col3, MinValue FROM YourTable CROSS APPLY (SELECT MIN(d) AS MinValue FROM (VALUES (Col1), (Col2), (Col3)) AS a(d)) A SQL Fiddle
Using CROSS APPLY: SELECT ID, Col1, Col2, Col3, MinValue FROM YourTable CROSS APPLY (SELECT MIN(d) AS MinValue FROM (VALUES (Col1), (Col2), (Col3)) AS a(d)) A SQL Fiddle
How about this: USE TargetDatabase GO INSERT INTO dbo.TargetTable(field1, field2, field3) SELECT field1, field2, field3 FROM SourceDatabase.dbo.SourceTable WHERE (some condition)
Here is slightly modified version. Changes are noted as code commentary. BEGIN TRANSACTION declare @cnt int declare @test nvarchar(128) — variable to hold table name declare @tableName nvarchar(255) declare @cmd nvarchar(500) — local means the cursor name is private to this code — fast_forward enables some speed optimizations declare Tests cursor local fast_forward for SELECT … Read more
For 2005 up, you can use SELECT [name] ,create_date ,modify_date FROM sys.tables I think for 2000, you need to have enabled auditing.
Behold, the filtered index. From the documentation (emphasis mine): A filtered index is an optimized nonclustered index especially suited to cover queries that select from a well-defined subset of data. It uses a filter predicate to index a portion of rows in the table. A well-designed filtered index can improve query performance as well as … Read more
You would mostly be using COUNT to summarize over a UID. Therefore COUNT([uid]) will produce the warning: Warning: Null value is eliminated by an aggregate or other SET operation. whilst being used with a left join, where the counted object does not exist. Using COUNT(*) in this case would also render incorrect results, as you … Read more
You can find the day of week and do a date add on days to get the start and end dates.. DATEADD(dd, -(DATEPART(dw, WeddingDate)-1), WeddingDate) [WeekStart] DATEADD(dd, 7-(DATEPART(dw, WeddingDate)), WeddingDate) [WeekEnd] You probably also want to look at stripping off the time from the date as well though.
A quick google points me to what looks like the solution. Open your EDMX in a file editor (or “open with…” in Visual Studio and select XML Editor). At the top you will find the storage model and it has an attribute ProviderManifestToken. This has should have the value 2008. Change that to 2005, recompile … Read more
I find UDFs are very handy and I use them all the time. I’m not sure what Microsoft’s rationale is for not including a sys.functions equivalent in SQL Server 2005 (or SQL Server 2008, as far as I can tell), but it’s easy enough to roll your own: CREATE VIEW my_sys_functions_equivalent AS SELECT * FROM … Read more
It is not the operator that is case sensitive, it is the column itself. When a SQL Server installation is performed a default collation is chosen to the instance. Unless explicitly mentioned otherwise (check the collate clause bellow) when a new database is created it inherits the collation from the instance and when a new … Read more