Skip to content

Instantly share code, notes, and snippets.

@osya
osya / gist:10b8c9aa7f43e9c59ecb
Last active August 29, 2015 14:11
MDX-запрос для проверки значений показателей в кубе по территоиям и по годам #MDX #BI #MIS
WITH
MEMBER [Measures].[СТАТ.ДЕМ.01] AS ([Measures].[VALUE], [Account].[Code].&[СТАТ.ДЕМ.01])
SELECT [Measures].[СТАТ.ДЕМ.01] on 0,
Non empty (
order(
[Territory].[Territories].[Федеральные округа]*[Calendar].[Year].[Year]
,[Calendar].[Year]. MemberValue, BDESC
)
) on 1
@osya
osya / gist:c8f7405b7064b63bfdc6
Created December 13, 2014 17:04
Нумерация строк в SSIS Script Task #BI #SSIS
' Microsoft SQL Server Integration Services Script Component
' Write scripts using Microsoft Visual Basic 2008.
' ScriptMain is the entry point class of the script.
Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper
Imports Microsoft.SqlServer.Dts.Runtime.Wrapper
@osya
osya / gist:fcb8ee63d79f4855d576
Last active August 29, 2015 14:11
Объединение результата запроса в одну строку #SQL
SELECT TOP 10 CAST(ACCOUNT_value_id AS NVARCHAR) + '...'
FROM [DM].[F_ACCOUNT_VALUE] FOR XML PATH('')
@osya
osya / gist:86ef7416c24b43ee6f70
Created December 13, 2014 17:06
MDX Level Counts #MDX #BI
--Количество уровней иерархии
WITH
MEMBER [Measures].[NumberOfLevels] AS
[Territory].[Territories]. Levels.Count
SELECT
[Measures].[NumberOfLevels] ON COLUMNS
FROM
[FRGS]
@osya
osya / gist:2271b319f6df764a66bd
Last active August 29, 2015 14:11
Replace white spaces with empty characters #SQL
--Tab, line feed and carriage return control characters have the values CHAR(9), CHAR(10) and CHAR(13) respectively.
cast(REPLACE(REPLACE(REPLACE(your_number_column,CHAR(9),”), CHAR(10),”),CHAR(13),”) as bigint)
http://bisherryli.com/2014/05/30/sql-54casting-numbers-with-white-spaces-as-integer-will-fail/
@osya
osya / gist:1c9cb700537b8d92fa78
Created December 13, 2014 17:12
Запрос, чтобы узнать какие объекты базы в какой файловой группе находятся #SQL
SELECT o .[name], o. [type], i.[name] , i .[index_id], f. [name]
FROM sys .indexes i
INNER JOIN sys. filegroups f
ON i .data_space_id = f .data_space_id
INNER JOIN sys. all_objects o
ON i .[object_id] = o .[object_id]
WHERE i .data_space_id = f .data_space_id
AND o .type = 'U' -- User Created Tables
ORDER BY f. [name]
---------------------------------------------------------------
@osya
osya / gist:4413e4ab6970b420f516
Created December 13, 2014 17:14
Генерация последовательности #SQL
WITH cte AS (
SELECT 1 i
UNION ALL
SELECT i +1 FROM cte WHERE i < 100
)
SELECT * FROM cte
OPTION ( maxrecursion 0 );
@osya
osya / gist:8a37dd509a4b548e5391
Created December 13, 2014 17:17
Default value for stored procedures parameter have to be constants. You'd need to do the following... #SQL
ALTER Procedure [dbo].[my_sp]@currentDate datetime = nullASIF @currentDate IS nullSET @currentDate = getdate()
URL: http://stackoverflow.com/questions/470664/sql-function-as-default-parameter-value
@osya
osya / gist:08535082e56c2aed7dee
Created December 13, 2014 17:18
Set database offline #SQL
ALTER DATABASE <dbname> SET OFFLINE WITH ROLLBACK IMMEDIATE
URL: http://stackoverflow.com/questions/808232/extreme-wait-time-when-taking-a-sql-server-database-offline
@osya
osya / gist:1cdb5fb76c01603c35c4
Created December 13, 2014 17:19
Search through SQL Agent Jobs (Поиск по джобам) #SQL
USE [msdb]
GO
SELECT j.job_id,
s.srvname,
j.name,
js.step_id,
js.command,
j.enabled
FROM dbo.sysjobs j
JOIN dbo.sysjobsteps js