Viewing 15 posts - 2,176 through 2,190 (of 2,462 total)
You could do something like this:
IF OBJECT_ID('tempdb..#indexInfo') IS NOT NULL
DROP TABLE #indexInfo;
SELECT TOP 0
t.TABLE_CATALOG AS db,
t.TABLE_SCHEMA AS SchemaName,
OBJECT_NAME(i.OBJECT_ID) AS TableName,
...
-- Itzik Ben-Gan 2001
August 1, 2013 at 9:48 am
TheSQLGuru (7/30/2013)
-- Itzik Ben-Gan 2001
July 31, 2013 at 3:27 pm
dkschill (7/30/2013)
CREATE TABLE #T (i TINYINT);
GO
INSERT INTO #T
SELECT ABS(CHECKSUM(NEWID())) % 250
GO 1000
;WITH t AS (SELECT i, ROW_NUMBER() OVER (ORDER BY i) AS n,...
-- Itzik Ben-Gan 2001
July 31, 2013 at 3:04 pm
ChrisM@Work (7/29/2013)
Thanks for the very generous feedback, Mr Kapsicum.If you're interested in how the method works, here's an excellent article by Dwain Camps[/url].
I have nothing to add to this thread...
-- Itzik Ben-Gan 2001
July 29, 2013 at 3:36 pm
Using this sample data:
--Adjust for the number of days of sample data you would like
DECLARE @days int = 1000;
IF OBJECT_ID('tempdb..#sales') IS NOT NULL
DROP TABLE #sales;
CREATE TABLE #sales
(sale_id int identity primary...
-- Itzik Ben-Gan 2001
July 29, 2013 at 3:28 pm
I asked this same question a few months back and got some good replies; just thought I'd share this:
http://www.sqlservercentral.com/Forums/Topic1397471-391-1.aspx
Check this out:
SELECT CAST(REPLICATE(CAST('' AS int),10) AS char(10)) AS...
-- Itzik Ben-Gan 2001
July 25, 2013 at 1:15 pm
Tobar (7/25/2013)
DECLARE @d DATETIME = '07/25/2013 10:11:12.345';
SELECT FORMAT ( @d, 'yyyy dd mm hh mm ss')
2013 25...
-- Itzik Ben-Gan 2001
July 25, 2013 at 1:01 pm
Eugene Elutin (7/25/2013)
Alan.B (7/24/2013)
Erland Sommarskog (7/24/2013)
Alan.B (7/24/2013)
Why is the SELECT@x=@x+ method not guaranteed to work?
Why would it?
See this KB article Pay particular attention to the first sentence under Cause.
I...
-- Itzik Ben-Gan 2001
July 25, 2013 at 12:30 pm
Erland Sommarskog (7/24/2013)
Alan.B (7/24/2013)
Why is the SELECT@x=@x+ method not guaranteed to work?
Why would it?
See this KB article Pay particular attention to the first sentence under Cause.
I say it would...
-- Itzik Ben-Gan 2001
July 24, 2013 at 4:38 pm
This would do the trick:
SELECT
CASE
WHEN ISNULL(rate,100)=100 THEN 1
ELSE 0
END AS Rate
FROM {yourtable}
-- Itzik Ben-Gan 2001
July 24, 2013 at 4:01 pm
Erland Sommarskog (7/24/2013)
SELECT substring(list, 1, len(list) - 1)FROM (SELECT list =
(SELECT DISTINCT name + ','
...
-- Itzik Ben-Gan 2001
July 24, 2013 at 3:57 pm
A couple techniques:
SELECT RIGHT(abc_col1,len(abc_col1)-2)
FROM tableA
SELECT REPLACE(abc_col1,'SH','')
FROM tableA
-- Itzik Ben-Gan 2001
July 24, 2013 at 2:54 pm
Here's another way... it's kind of a "Quirky-Coalesce":
-- sample data
DECLARE @Production_Product TABLE (name varchar(10));
INSERT INTO @Production_Product VALUES ('aaa'),('bbb'),('ccc'),('ccc');
DECLARE @listStr varchar(max)='';
SELECT @listStr=@listStr+
CASE
WHEN @listStr='' THEN ''+name
ELSE ','+name
END
FROM (SELECT DISTINCT name FROM...
-- Itzik Ben-Gan 2001
July 24, 2013 at 2:46 pm
NineIron (7/24/2013)
-- Itzik Ben-Gan 2001
July 24, 2013 at 1:14 pm
Luis Cazares (7/18/2013)
No, you can't because the alias doesn't exist when the JOIN is processed.
You can get around that doing something like this (using my own sample code...
-- Itzik Ben-Gan 2001
July 18, 2013 at 1:59 pm
Viewing 15 posts - 2,176 through 2,190 (of 2,462 total)