How to get calendar Quarter from a date in TSQL
SELECT DATEPART(QUARTER, @date) This returns the quarter of the @date, assuming @date is a DATETIME.
SELECT DATEPART(QUARTER, @date) This returns the quarter of the @date, assuming @date is a DATETIME.
One is a date and time, the other is a column type that is updated every time a row is updated. [Note timestamp is being deprecated; use rowversion instead]
If the object was recently created, you can check the Schema Changes History report, within the SQL Server Management Studio, which “provides a history of all committed DDL statement executions within the Database recorded by the default trace”: You then can search for the create statements of the objects. Among all the information displayed, there … Read more
Yes. You need to use the “Searched” form rather than the “Simple” form of the CASE expression SELECT CASE WHEN c.Number IN ( ‘1121231’, ‘31242323’ ) THEN 1 WHEN c.Number IN ( ‘234523’, ‘2342423’ ) THEN 2 END AS Test FROM tblClient c
You can do some trick: ORDER BY (CASE WHEN [Order] IS NULL THEN 0 ELSE 1 END), [Order]
In SQL 2005 you can use management views to find slow running queries. A good script i found a while ago on SQL server performance will help get you started; it lists data with the slowest performing first. SELECT creation_time ,last_execution_time ,total_physical_reads ,total_logical_reads ,total_logical_writes , execution_count , total_worker_time , total_elapsed_time , total_elapsed_time / execution_count avg_elapsed_time … Read more
You can use the ROWLOCK hint, but AFAIK SQL may decide to escalate it if it runs low on resources From the doco: ROWLOCK Specifies that row locks are taken when page or table locks are ordinarily taken. When specified in transactions operating at the SNAPSHOT isolation level, row locks are not taken unless ROWLOCK … Read more
The primary key is a unique key in your table that you choose that best uniquely identifies a record in the table. All tables should have a primary key, because if you ever need to update or delete a record you need to know how to uniquely identify it. A surrogate key is an artificially … Read more
That should do: select( SELECT col1 FROM table1 WHERE col2 = ‘x’ ORDER by col3 FOR XML path(”) ) as myName Not pretty but should give the result that you need
On the one hand you could use sp_executesql: exec sp_executesql N’select @rowcount=count(*) from anytable’, N’@rowcount int output’, @rowcount output; On the other hand you could use a temporary table: declare @result table ([rowcount] int); insert into @result ([rowcount]) exec (N’select count(*) from anytable’); declare @rowcount int = (select top (1) [rowcount] from @result);