Converting MDX query into SQL Server 2008
We have MDX query based OLAP CUbes.
To reduce MDX based dependenies, we have to convert MDX based cube to sql server 2008 based queries.
For this I need expert advise to convert below query to sql server 2008 based query :
CREATE MEMBER CURRENTCUBE.Measures.[Ack Lost]
AS 'Sum(PeriodsToDate([Time].[Year], [Time].CurrentMember ), [Measures].[Lost])',
FORMAT_STRING = "#,#",
VISIBLE = 1;
Hi Sachin,
According to your description, you need to convert the MDX query to T-SQL query, right?
Your MDX query is calculated measure that return the total value from the first sibling and ending with the given member. In T-SQL query we can use the query as Yogisha provided to achieve the same requirement. Now you need to a tool to convert all the MDX
related SSAS cube queries to MS SQL Server 2008 based queries.
Although MDX has some similarities with T-SQL these languages are in many ways different. Beginning to learn and comprehend SQL Server Analysis Services (SSAS) MDX queries can be difficult after one has spent years writing queries in T-SQL. Currently, there
is no such a tool to convert a MDX query to T-SQL query since the structure difference between MDX and T-SQL. So you need to convert them manually, please refer to the links below to see the details.
http://www.mssqltips.com/sqlservertip/2916/comparison-of-queries-written-in-tsql-and-sql-server-mdx/
https://sqlmate.wordpress.com/2013/11/12/t-sql-vs-mdx-2/
http://technet.microsoft.com/en-us/library/aa216779(v=sql.80).aspx
Regards,
Charlie Liao
TechNet Community Support
Similar Messages
-
Best way to migrate SharePoint 2003 data into SQL Server 2008
Hi Experts,
I am planning to migrate data from SharePoint 2003 into SQL Server 2008. After the migration SharePoint site will be deleted in couple of months and then that data will be feed into .Net Front end application
1) What is the best and easy way to do it?
2) Is there any way to automate the migration process? i.e. If a new record gets entered into SharePoint it should be populated into SQL Server 2008.
3) Any other suggestions
Thanks,
JohnDear John,
If it's just a few lists, and you just want to import them "as-is" then it should be possible to do so ... and survive to tell the about it ;-)
Generally speaking, You will need to write a small process (program or script) to read/parse each list and check if the item(s) are in the target table (I assuming that there is a distinct table as target
for each list, and that each list has 'something" you can use to distinct each row), if it's not there, the just add them according to your needs.
Then just rerun the process periodically and it would keep your databases up to date (you could even set ti up to update those records that have changes, but that would delay your process significantly)
What i just described is doable, and not TOO complicated, it could be done i a lot different ways, and with different alternatives of programming/scripting languages. for sure you can do it in any flavor
of .net language, and even powershell.
As I mentioned, this is speaking in general, the actual implementation would depend on your specific needs and the kind of data that you have/need to keep.
Best Regards / Saludos, Marianok
Disclaimer: This post, and all included code and information is provided "AS IS" with no warranties or guarantees and confers no rights. Try it at your own risk, I take no responsibilities.
Aclaración: Esta publicación, y todo en código e información en la misma, es provista "AS IS" / "Como Está" sin garantía alguna y no le confiere ningún derecho. Pruebelo su propio riesgo. No asumo responsabilidad alguna. -
Load flat files from S3 into SQL Server 2008 R2
Hi, We have a few customers dropping files in Amazon S3. Could you please let me know how to load this data into SQL Server 2008 R2 database using SSIS? We are 2008 R2 BIDS environment.
Thanks in advance..............
IoneHi ione721,
You can install the PostgreSQL ODBC driver so that you can use the .Net Providers\Odbc Data Provider for ADO.NET Source component to connect to the Amazon cloud storage. After that, you can use a OLE DB Destination to load the data to SQL Server database.
Reference:
http://docs.aws.amazon.com/redshift/latest/mgmt/configure-odbc-connection.html
Regards,
Mike Yin
TechNet Community Support -
Require help with Pivot table query in SQL Server 2008
Hi,
I have a query regarding converting columns to rows in SQL Server 2008. Please look at the table below.
I need the output to look something like this :
The columns for the children can be dynamic or fixed ( max of 6 children) based on the Family_ID. For Example: A family can have 1 child or more than 1 child.
Not sure how to go about it. Would appreciate your help :)Looks like you need dynamic pivot on multiple columns. I have two articles on this topic, start from this one
T-SQL:
Dynamic Pivot on Multiple Columns
It has reference to my other blog post.
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articles -
Converting Oracle query to Sql Server with date manipulation
The following SSIS statement works great in Oracle, and it parses successfully in the "Sql Task" window. In Oracle it returns
this result:
FROM_DT THRU_DT
16-Jan-2014 23-Jan-2014
select
case
when to_char(to_date(sysdate,'dd-mon-yyyy'),'dd') <=7 then to_date('24'||to_char(add_months(sysdate,-1),'mmyyyy'),'ddmmyyyy')
when to_char(to_date(sysdate,'dd-mon-yyyy'),'dd') <=15 then to_date('01'||to_char(sysdate,'mmyyyy'),'ddmmyyyy')
when to_char(to_date(sysdate,'dd-mon-yyyy'),'dd') <=23 then to_date('08'||to_char(sysdate,'mmyyyy'),'ddmmyyyy')
else to_date('16'||to_char(sysdate,'mmyyyy'),'ddmmyyyy')
end as from_dt,
case
when to_char(to_date(sysdate,'dd-mon-yyyy'),'dd') <=7 then trunc(last_day(add_months(sysdate,-1)))
when to_char(to_date(sysdate,'dd-mon-yyyy'),'dd') <=15 then to_date('07'||to_char(sysdate,'mmyyyy'),'ddmmyyyy')
when to_char(to_date(sysdate,'dd-mon-yyyy'),'dd') <=23 then to_date('15'||to_char(sysdate,'mmyyyy'),'ddmmyyyy')
else to_date('23'||to_char(sysdate,'mmyyyy'),'ddmmyyyy')
end as thru_dt
from sys.dual
How can I convert this to Sql Server ?>>You mean you get the data from Oracle and tries to insert it into SQL Server?
- no, sorry, I want to convert the syntax to Sql Server
>>Are
you running the query in OLEDB provider connected to the Oracle's database?
- yes, this works fine now (after fixing this redundancy:
to_char(to_date(sysdate,'dd-mon-yyyy'),'dd')change toto_char(sysdate,'dd') -
How to convert MDX query to SQL
Hi everyone,
can you please suggest me, how to convert the below mdx query to sql query. can you please tell me what it is doing?
CREATE MEMBER CURRENTCUBE.[Measures].[calculation]
AS IIF(([Measures].[Clear Call Count],[Trouble Code].[Is Battery].&[Battery T-Code],[Service Provider].[Is Towmark].&[Towmark],[Provider Technician].[Is Towmark].&[Towmark]) = 0, NULL,
([Measures].[ Total Shipped],[Service Provider].[Is Towmark].&[Towmark],[Provider Technician].[Is Towmark].&[Towmark])/
([Measures].[Clear Call Count],[Trouble Code].[Is Battery].&[Battery T-Code],[Service Provider].[Is Towmark].&[Towmark],[Provider Technician].[Is Towmark].&[Towmark])),
FORMAT_STRING = "Percent",
VISIBLE = 1 , ASSOCIATED_MEASURE_GROUP = 'Sale';
Thanks
VishuHi Vishu,
As Olaf said, this is a calculated member which used in MDX script in your cube, we cannot execute it in SQL Server Management Studio directly. Here are some document about calculated members and MDX script for your reference.
Defining Calculated Members
MDX Scripting Fundamentals (Analysis Services)
Regards,
Charlie Liao
TechNet Community Support -
Export SQL Express Database into SQL Server 2008 R2
We have an application using SQL express and want to export it's database into our more centralised SQL Server 2008 R2
Can this be done? What steps should I take?We have an application using SQL express and want to export it's database into our more centralised SQL Server 2008 R2
Can this be done? What steps should I take?
What is version of you SQL server express if it is 2008 and above you can use Import export wizard to move data.You can do by backup also but if your requirement is just to move data use Imp export wizard see below link
http://blog.winhost.com/exporting-sql-server-data-with-import-and-export-wizard/
Please mark this reply as the answer or vote as helpful, as appropriate, to make it useful for other readers -
Connecting JDBC Single Row Query to SQL Server 2008
Hello,
I am new to workbench and am having a very dificult time accessing a database and running a query on it. I have searched a lot on the internet for suggestion on how to accomplish this but nothing has worked. The LiveCycle was intaled on the same server that the SQL Server is sintalled, and was installed by an administrator who is no longer at our company. So I am trying to have the user input an account number into the form I have created, then take that account number and use an xpath expression to query the database and extract the information for that account. Could anyone please help me set this up.
I Changed my my-db2-ds.xml to the following:
<local-tx-datasource>
<jndi-name>SQLDB_IMACS</jndi-name>
<connection-url>jdbc:sqlserver://CBS-SQL-001;databaseName=DB_IMACS;integratedSecurity=tru e;</connection-url>
<driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>
</local-tx-datasource>
and I get the following error message:
Exception: Could not create connection; - nested throwable: (org.jboss.resource.JBossResourceException: Failed to register driver for: com.microsoft.sqlserver.jdbc.SQLServerDriver; - nested throwable: (java.lang.ClassNotFoundException: No ClassLoaders found for: com.microsoft.sqlserver.jdbc.SQLServerDriver)); - nested throwable: (org.jboss.resource.JBossResourceException: Could not create connection; - nested throwable: (org.jboss.resource.JBossResourceException: Failed to register driver for: com.microsoft.sqlserver.jdbc.SQLServerDriver; - nested throwable: (java.lang.ClassNotFoundException: No ClassLoaders found for: com.microsoft.sqlserver.jdbc.SQLServerDriver)))
I have the following file sqljdbc.jar in my Adobe LiveCycle ES2\jboss\server\lc_turnkey\lib\ folder.
If you could please let me know what I can do to connect that would be very useful.
Thanks,
sgarciacode19You will need to use the UNPIVOT operator:
DECLARE @example TABLE
Id int NOT NULL IDENTITY(1,1),
Quantity1 int,
Quantity2 int,
Quantity3 int
INSERT INTO @example VALUES (1000, 2000, 3000), (4000, 5000, 6000);
SELECT * FROM @example;
SELECT Id, Quantity, QuantityType
FROM @example
UNPIVOT
Quantity FOR QuantityType IN (Quantity1, Quantity2, Quantity3)
) AS u;
Output:
(2 row(s) affected)
Id Quantity1 Quantity2 Quantity3
1 1000 2000 3000
2 4000 5000 6000
(2 row(s) affected)
Id Quantity QuantityType
1 1000 Quantity1
1 2000 Quantity2
1 3000 Quantity3
2 4000 Quantity1
2 5000 Quantity2
2 6000 Quantity3
(6 row(s) affected) -
I am using Excel source which uses Microsoft ACE 12.0 OLE DB provider, this only allows the first 255 columns to be imported and not the rest.
I need to export all the columns into the table .
Any pointers to this is greatly appreciatedIf you can use third-party solutions, check the commercial COZYROC Excel adapters:
Excel Connection Plus Manager
Excel Source Plus
Excel Destination Plus
Excel Task
The enhanced components can be used both under 32bit and 64bit modes and doesn't exhibit the 255 columns limitation.
SSIS Tasks Components Scripts Services | http://www.cozyroc.com/ -
Get definition of an index from query in SQL Server
Hi,
I need to get definition of an index using query in SQL Server 2008 as we can get definition of a stored procedure using sp_helptext command.
Thanks In advance,
JiteshI have worked on the script and updated the script as per my need. Now I am able to generate the script for a specific index. Here is the script:-
CREATE PROCEDURE ScriptCreateDropIndexes_SP
@TableName SYSNAME
,@SchemaName SYSNAME = 'dbo'
,@SORT_IN_TEMPDB VARCHAR(3) = 'OFF'
,@DROP_EXISTING VARCHAR(3) = 'OFF'
,@STATISTICS_NORECOMPUTE VARCHAR(3) = 'OFF'
,@ONLINE VARCHAR(3) = 'OFF'
,@Index_Name NVARCHAR(1000)
,@is_Create int = 0
AS
Parameters
@Schemaname - SchemaName to which the table belongs to. Default value 'dbo'.
@Tablename - TableName for which the Indexes need to be scripted.
@SORT_IN_TEMPDB - Runtime value for SORT_IN_TEMPDB option in create index.
Valid Values ON \ OFF. Default = 'OFF'
@DROP_EXISTING - Runtime value for DROP_EXISTING option in create index.
Valid Values ON \ OFF. Default = 'OFF'
@STATISTICS_NORECOMPUTE - Runtime value for STATISTICS_NORECOMPUTE option in create index.
Valid Values ON \ OFF. Default = 'OFF'
@ONLINE - Runtime value for ONLINE option in create index.
Valid Values ON \ OFF. Default = 'OFF'
SET NOCOUNT ON
IF @SORT_IN_TEMPDB NOT IN ('ON','OFF')
BEGIN
RAISERROR('Valid value for @SORT_IN_TEMPDB is ON \ OFF',16,1)
RETURN
END
IF @DROP_EXISTING NOT IN ('ON','OFF')
BEGIN
RAISERROR('Valid value for @DROP_EXISTING is ON \ OFF',16,1)
RETURN
END
IF @STATISTICS_NORECOMPUTE NOT IN ('ON','OFF')
BEGIN
RAISERROR('Valid value for @STATISTICS_NORECOMPUTE is ON \ OFF',16,1)
RETURN
END
IF @ONLINE NOT IN ('ON','OFF')
BEGIN
RAISERROR('Valid value for @ONLINE is ON \ OFF',16,1)
RETURN
END
DECLARE @IDXTable TABLE
Schema_ID INT
,Object_ID INT
,Index_ID INT
,SchemaName SYSNAME
,TableName SYSNAME
,IndexName SYSNAME
,IsPrimaryKey BIT
,IndexType INT
,CreateScript VARCHAR(MAX) NULL
,DropScript VARCHAR(MAX) NULL
,ExistsScript VARCHAR(MAX) NULL
,Processed BIT NULL
INSERT INTO @IDXTable
Schema_ID
,Object_ID
,Index_ID
,SchemaName
,TableName
,IndexName
,IsPrimaryKey
,IndexType
SELECT ST.Schema_id
,ST.Object_id
,SI.Index_id
,SCH.Name
,ST.Name
,SI.Name
,SI.is_primary_key
,SI.Type
FROM SYS.INDEXES SI
JOIN SYS.TABLES ST
ON SI.Object_ID = ST.Object_ID
JOIN SYS.SCHEMAS SCH
ON SCH.schema_id = ST.schema_id
WHERE SCH.Name = 'dbo'
AND ST.Name = 'group_master'
AND SI.name = 'uq_group_master__parent_id'
AND SI.Type IN (1,2,3)
DECLARE @SchemaID INT
DECLARE @TableID INT
DECLARE @IndexID INT
DECLARE @isPrimaryKey BIT
DECLARE @IndexType INT
DECLARE @CreateSQL VARCHAR(MAX)
DECLARE @IndexColsSQL VARCHAR(MAX)
DECLARE @WithSQL VARCHAR(MAX)
DECLARE @IncludeSQL VARCHAR(MAX)
DECLARE @WhereSQL VARCHAR(MAX)
DECLARE @SQL VARCHAR(MAX)
DECLARE @DropSQL VARCHAR(MAX)
DECLARE @ExistsSQL VARCHAR(MAX)
DECLARE @IndexName SYSNAME
DECLARE @TblSchemaName SYSNAME
SELECT @TblSchemaName = QUOTENAME(@Schemaname) + '.' + QUOTENAME(@TableName)
SELECT @CreateSQL = ''
SELECT @IndexColsSQL = ''
SELECT @WithSQL = ''
SELECT @IncludeSQL = ''
SELECT @WhereSQL = ''
WHILE EXISTS(SELECT 1
FROM @IDXTable
WHERE CreateScript IS NULL)
BEGIN
SELECT TOP 1 @SchemaID = Schema_ID
,@TableID = Object_ID
,@IndexID = Index_ID
,@isPrimaryKey = IsPrimaryKey
,@IndexName = IndexName
,@IndexType = IndexType
FROM @IDXTable
WHERE CreateScript IS NULL
AND SchemaName = @SchemaName
AND TableName = @TableName
ORDER BY Index_ID
IF @isPrimaryKey = 1
BEGIN
SELECT @ExistsSQL = ' EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N''' + @TblSchemaName + ''') AND name = N''' + @IndexName + ''')'
SELECT @DropSQL = ' ALTER TABLE '+ @TblSchemaName + ' DROP CONSTRAINT [' + @IndexName + ']'
END
ELSE
BEGIN
SELECT @ExistsSQL = ' EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N''' + @TblSchemaName + ''') AND name = N''' + @IndexName + ''')'
SELECT @DropSQL = ' DROP INDEX [' + @IndexName + '] ON ' + @TblSchemaName
END
IF @IndexType IN (1,2)
BEGIN
SELECT @CreateSQL = CASE
WHEN SI.is_Primary_Key = 1 THEN
'ALTER TABLE ' + @TblSchemaName
+ ' ADD CONSTRAINT [' + @IndexName + '] PRIMARY KEY ' + SI.type_desc
WHEN SI.Type IN (1,2) THEN
' CREATE ' + CASE SI.is_Unique
WHEN 1 THEN ' UNIQUE ' ELSE '' END + SI.type_desc + ' INDEX ' + QUOTENAME(SI.Name) + ' ON ' + @TblSchemaName
END
,@IndexColsSQL = ( SELECT SC.Name + ' '
+ CASE SIC.is_descending_key
WHEN 0 THEN ' ASC '
ELSE 'DESC'
END + ','
FROM SYS.INDEX_COLUMNS SIC
JOIN SYS.COLUMNS SC
ON SIC.Object_ID = SC.Object_ID
AND SIC.Column_ID = SC.Column_ID
WHERE SIC.OBJECT_ID = SI.Object_ID
AND SIC.Index_ID = SI.Index_ID
AND SIC.is_included_column = 0
ORDER BY SIC.Key_Ordinal
FOR XML PATH('')
,@WithSQL =' WITH (PAD_INDEX = ' + CASE SI.is_padded WHEN 1 THEN 'ON' ELSE 'OFF' END + ',' + CHAR(13) +
' IGNORE_DUP_KEY = ' + CASE SI.ignore_dup_key WHEN 1
THEN 'ON' ELSE 'OFF' END + ',' + CHAR(13) +
' ALLOW_ROW_LOCKS = ' + CASE SI.Allow_Row_Locks WHEN
1 THEN 'ON' ELSE 'OFF' END + ',' + CHAR(13) +
' ALLOW_PAGE_LOCKS = ' + CASE SI.Allow_Page_Locks WHEN
1 THEN 'ON' ELSE 'OFF' END + ',' + CHAR(13) +
CASE SI.Type WHEN 2 THEN 'SORT_IN_TEMPDB = ' + @SORT_IN_TEMPDB
+',DROP_EXISTING = ' + @DROP_EXISTING + ',' ELSE '' END +
CASE WHEN SI.Fill_Factor > 0 THEN ' FILLFACTOR =
' + CONVERT(VARCHAR(3),SI.Fill_Factor) + ',' ELSE '' END +
' STATISTICS_NORECOMPUTE = ' + @STATISTICS_NORECOMPUTE
+ ', SORT_IN_TEMPDB = ' + @SORT_IN_TEMPDB +
', ONLINE = ' + @ONLINE + ') ON ' + QUOTENAME(SFG.Name)
,@IncludeSQL = ( SELECT QUOTENAME(SC.Name) + ','
FROM SYS.INDEX_COLUMNS SIC
JOIN SYS.COLUMNS SC
ON SIC.Object_ID = SC.Object_ID
AND SIC.Column_ID = SC.Column_ID
WHERE SIC.OBJECT_ID
= SI.Object_ID
AND SIC.Index_ID = SI.Index_ID
AND SIC.is_included_column = 1
ORDER BY SIC.Key_Ordinal
FOR
XML PATH('')
,@WhereSQL = SI.Filter_Definition
FROM SYS.Indexes SI
JOIN SYS.FileGroups SFG
ON SI.Data_Space_ID =SFG.Data_Space_ID
WHERE Object_ID = @TableID
AND Index_ID = @IndexID
SELECT @IndexColsSQL = '(' + SUBSTRING(@IndexColsSQL,1,LEN(@IndexColsSQL)-1) + ')'
IF LTRIM(RTRIM(@IncludeSQL)) <> ''
SELECT @IncludeSQL = ' INCLUDE (' + SUBSTRING(@IncludeSQL,1,LEN(@IncludeSQL)-1) + ')'
IF LTRIM(RTRIM(@WhereSQL)) <> ''
SELECT @WhereSQL = ' WHERE (' + @WhereSQL + ')'
END
IF @IndexType = 3
BEGIN
SELECT @CreateSQL = ' CREATE ' + CASE
WHEN SI.Using_xml_index_id IS NULL THEN ' PRIMARY '
ELSE '' END
+ SI.type_desc + ' INDEX ' + QUOTENAME(SI.Name) + ' ON ' + @TblSchemaName
,@IndexColsSQL = ( SELECT SC.Name + ' '
+ ','
FROM SYS.INDEX_COLUMNS SIC
JOIN SYS.COLUMNS SC
ON SIC.Object_ID = SC.Object_ID
AND SIC.Column_ID = SC.Column_ID
WHERE SIC.OBJECT_ID = SI.Object_ID
AND SIC.Index_ID = SI.Index_ID
AND SIC.is_included_column = 0
ORDER BY SIC.Key_Ordinal
FOR XML PATH('')
,@WithSQL =' WITH (PAD_INDEX = ' + CASE SI.is_padded WHEN 1 THEN 'ON' ELSE 'OFF' END + ',' + CHAR(13) +
' ALLOW_ROW_LOCKS = ' + CASE SI.Allow_Row_Locks WHEN
1 THEN 'ON' ELSE 'OFF' END + ',' + CHAR(13) +
' ALLOW_PAGE_LOCKS = ' + CASE SI.Allow_Page_Locks WHEN
1 THEN 'ON' ELSE 'OFF' END + ',' + CHAR(13) +
CASE SI.Type WHEN 2 THEN 'SORT_IN_TEMPDB = OFF,DROP_EXISTING
= OFF,' ELSE '' END +
CASE WHEN SI.Fill_Factor > 0 THEN ' FILLFACTOR =
' + CONVERT(VARCHAR(3),SI.Fill_Factor) + ',' ELSE '' END +
'SORT_IN_TEMPDB = OFF ' + ') '
,@IncludeSQL = ' USING XML INDEX [' + (SELECT Name
FROM SYS.XML_Indexes SIP
WHERE SIP.Object_ID = SI.Object_ID
AND SIP.Index_ID = SI.Using_XML_Index_ID) + '] FOR PATH '
FROM SYS.XML_Indexes SI
WHERE SI.Object_ID = @TableID
AND SI.Index_ID = @IndexID
SELECT @IndexColsSQL = '(' + SUBSTRING(@IndexColsSQL,1,LEN(@IndexColsSQL)-1) + ')'
END
SELECT @CreateSQL = @CreateSQL
+ @IndexColsSQL + CASE WHEN @IndexColsSQL <> '' THEN CHAR(13) ELSE ''
END
+ ISNULL(@IncludeSQL,'') + CASE WHEN @IncludeSQL <> '' THEN CHAR(13) ELSE
'' END
+ ISNULL(@WhereSQL,'') + CASE WHEN @WhereSQL <> '' THEN CHAR(13) ELSE
'' END
--+ @WithSQL
UPDATE @IDXTable
SET CreateScript = @CreateSQL
,DropScript = @DropSQL
,ExistsScript = @ExistsSQL
WHERE Schema_ID = @SchemaID
AND Object_ID = @TableID
AND Index_ID = @IndexID
END
-- PRINT REPLICATE('-',100)
-- PRINT 'DROP Indexes'
-- PRINT REPLICATE('-',100)
if @is_Create = 0
begin
UPDATE @IDXTable
SET Processed = 0
WHERE SchemaName = @SchemaName
AND TableName = @TableName
WHILE EXISTS(SELECT 1
FROM @IDXTable
WHERE ISNULL(Processed,0) = 0
AND SchemaName = @SchemaName
AND TableName = @TableName )
BEGIN
SELECT @SQL = ''
SELECT TOP 1 @SchemaID = Schema_ID
,@TableID = Object_ID
,@IndexID = Index_ID
,@SQL = 'IF ' + ExistsScript + CHAR(13) + DropScript + CHAR(13)
FROM @IDXTable
WHERE ISNULL(Processed,0) = 0
AND SchemaName = @SchemaName
AND TableName = @TableName
ORDER BY IndexType DESC,Index_id DESC
PRINT @sql
UPDATE @IDXTable
SET Processed = 1
WHERE Schema_ID = @SchemaID
AND Object_ID = @TableID
AND Index_ID = @IndexID
END
end
--PRINT REPLICATE('-',100)
--PRINT 'Create Indexes'
-- PRINT REPLICATE('-',100)
if @is_Create = 1
begin
UPDATE @IDXTable
SET Processed = 0
WHERE SchemaName = @SchemaName
AND TableName = @TableName
WHILE EXISTS(SELECT 1
FROM @IDXTable
WHERE ISNULL(Processed,0) = 0
AND SchemaName = @SchemaName
AND TableName = @TableName )
BEGIN
SELECT @SQL = ''
SELECT TOP 1 @SchemaID = Schema_ID
,@TableID = Object_ID
,@IndexID = Index_ID
,@SQL = 'IF NOT ' + ExistsScript + CHAR(13) + CreateScript + CHAR(13)
FROM @IDXTable
WHERE ISNULL(Processed,0) = 0
AND SchemaName = @SchemaName
AND TableName = @TableName
ORDER BY IndexType DESC,Index_id DESC
PRINT @sql
UPDATE @IDXTable
SET Processed = 1
WHERE Schema_ID = @SchemaID
AND Object_ID = @TableID
AND Index_ID = @IndexID
END
end -
Isse with using Grouping Sets in SQL Server 2008 R2
Hi,
I created a query in SQL Server 2012 using grouping sets that works fine. When I try to use the same query in SQL Server 2008 I get an error ("Inccorrect syntax near SETS").
I researched using grouping sets in 2008 and didn't see any issue with my query. What is different in grouping sets 2008 vs 2012?
SELECT tl.ClientRegionCd as [Client Region Code] , tl.ClientRegionDesc as [Region Name], count(tl.CompleteICN) as [Trauma Letters Sent]
from TORT_Trauma_Letters tl
Where CONVERT(VARCHAR(26), tl.SecondNoticeSent, 23) between '2014-06-12' and '2014-06-12'
GROUP BY GROUPING SETS((tl.ClientRegionCd, tl.ClientRegionDesc), ())
StacieCheck this blog post as how to deal with date ranges
http://sqlblog.com/blogs/aaron_bertrand/archive/2009/10/16/bad-habits-to-kick-mishandling-date-range-queries.aspx
For your result you can simply achieve your result with UNION ALL, e.g.
select Client, Region, Letters
from myTable
UNION ALL
select NULL, NULL, SUM(letters) as Letters
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articles -
How to convert rows to columns in sql server 2008
How to convert rows to columns in sql server 2008 using the GROUP BY function? (only one query allowed)
Lookup the Pivot transformation. From BOL:
The Pivot transformation makes a normalized data set into a less normalized
but more compact version by pivoting the input data on a column value. For
example, a normalized Orders data set that lists customer name, product, and quantity purchased typically has multiple rows for any customer who purchased multiple products, with each row for that customer showing order
details for a different product. By pivoting the data set on the product column, the Pivot transformation can output a data set with a
single row per customer. That single row lists all the purchases by the customer, with the product names shown as column names, and the quantity shown as a value in the product column. Because not every customer purchases every product, many columns may contain
null values.
When a dataset is pivoted, input columns perform different roles in the pivoting process. A column can participate in the following ways:
The column is passed through unchanged to the output. Because many input rows
can result only in one output row, the transformation copies only the first
input value for the column.
The column acts as the key or part of the key that identifies a set of
records.
The column defines the pivot. The values in this column are associated with
columns in the pivoted dataset.
The column contains values that are placed in the columns that the pivot
creates.
Paul -
How to convert the following query to sql server 2005
hi
i have the following query in ms access and i want to convert it into sql server 2005 express edition
SELECT iif(Max(BNo) is null,1,Max(BNo)+1) AS BNo from ( SELECT iif(Max(Product.BNo) is null,0,Max(Product.BNo)) AS BNo FROM Product union all SELECT iif(Max(grndetail.BNo) is null,0,Max(grndetail.BNo)) AS BNo FROM grndetail UNION ALL SELECT iif(Max(srdetail.BNo) is null,0,Max(srdetail.BNo)) AS BNo FROM srdetail ) as t
how to do thisThe construct involving case when MAX sounds suspicious. Can you explain what the query is supposed to be doing, the structure of your table, then we can re-write it?
E.g. if you provide your table, some data and desired result, you'll get better answer than direct translation of this suspicious query.
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articles -
Hi,
I have to implement the following scenario in SSIS but don't know how to do since I never worked with SSIS before. Please help me.
I have 20 different text files in a single folder and 20 different tables corresponding to each text file in SQL Server 2008 R2 Database. I need to extract the data from each text file and
load the data into corresponding table in Sql Server Database. Please guide me in how many ways I can do this and which is the best way to implement this job. Actually I have to automate this job. Few files are in same format(with same column names
and datatypes) where others are not.
1. Do I need to create 20 different projects ?
or
Can I implement this in only one project by having 20 packages?
or
Can I do this in one project with only one package?
Thanks in advance.As I said I don't know how to use object data type, I just given a shot as below. I know the following code has errors can you please correct it for me.
Public
Sub Main()
' Add your code here
Dim f1
As FileStream
Dim s1
As StreamReader
Dim date1
As
Object
Dim rline
As
String
Dim Filelist(1)
As
String
Dim FileName
As
String
Dim i
As
Integer
i = 1
date1 =
Filelist(0) =
"XYZ"
Filelist(1) =
"123"
For
Each FileName
In Filelist
f1 = File.OpenRead(FileName)
s1 = File.OpenText(FileName)
rline = s1.ReadLine
While
Not rline
Is
Nothing
If Left(rline, 4) =
"DATE"
Then
date1 (i)= Mid(rline, 7, 8)
i = i + 1
Exit
While
End
If
rline = s1.ReadLine
End
While
Next
Dts.Variables(
"date").Value = date1(1)
Dts.Variables(
"date1").Value = date1(2)
Dts.TaskResult = ScriptResults.Success
End
Sub -
Cannot kill a session that is running a query on a linked server in SQL Server 2008 R2
Hi,
Cannot kill a session that is running a query on a linked server in SQL Server 2008 R2.
When I try to kill, it status shown as "KILLED/ROLLBACK"
I have facing the issue from long back. I searched many and none of them worked for me
Any help is greatly appreciated
Thanks
Jaison
CarverI guess its stuck, can you see some blocking or any other process blocking the rollback.
can you check rollback status using below command. Or you can use sp_who2 and check status column
select percent_complete,estimated_completion_time from sys.dm_exec_requests
where spid=xxx
Please mark this reply as answer if it solved your issue or vote as helpful if it helped so that other forum members can benefit from it.
My TechNet Wiki Articles
Maybe you are looking for
-
VERY slow performance with CS4 + Save for web
Note: I have done a search for similar issues but can find nothing regarding CS4 and this particular issue. I'm using a MacBook Pro 2.4Ghz w/4GB of RAM and resources are aplenty when the issue occurs. Issue My problem is that under certain circumstan
-
Minor issue: Upgrade won't let ISolitaire game load. Major issue: iPhone 3G has slowed after iOS4 upgrade to snail's pace opening apps and other stuff. Does anyone know why? I suspect a fix should be on the way. Hopefully. Or is this a ploy to get us
-
Java Access Bridge and the JRE
Hi i want to get access to an application that uses its own JRE. but somehow i have huge problems to do this. Some info: Win7 x64 Visual Studio 2010 java se 7_u7 win 32 applikation Target apps JRE is JSE 6 I want to read the contents in the app. But
-
Wrong costing variant defaulting in CK40n
Hello Gurus, I have a strange issue, cost estimate was released for a material with wrong costing variant. Using costing reorganization CKR1 i deleted this standard cost estimate. I checked KEKO and KEPH, no cost estimate exist in that plant for the
-
Hey there. Since the update to the new Gnome and GDM, i am unable to type '@' or any other character that i used to type using the alt gr key. The old GDM, had a toolbar in the bottom in which i could select keymap, DE, and language (i think =P), the