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), ())
Stacie

Check 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

Similar Messages

  • How to sort specific column when using GROUPING SETS in SQL Server?

    If I remember correctly, in SQL Server, it is not recommended to use "ORDER BY" when there's already a GROUP BY GROUPING SETS.
    I have two columns: [UPC#] & [Description] both are varchar.
    My grouping sets is like this:
    GROUP BY
    GROUPING SETS
    ([UPC],[Description])
    I don't have 'ORDER BY' but it's automatically sorting the Description column.
    If I added a 3rd column, sum(Qty), then it doesn't sort by Description anymore. But if I added
    ORDER BY [Description]
    then the grand total of sum(Qty) will be at the first row instead of the last.
    Is there a way to sort the Description column and still let the grand total of sum(Qty) be at the last row instead?
    Thanks.

    Yes, it works.
    Thank you.
    Could you kindly explain the logic?
    I don't quite understand the "= 3 THEN 1 ELSE 0" part.
    Is the #3 mean the column index 3?
    GROUPING_ID returns a bit mask value depending on number of columns grouped in the result 
    So when you do GROUPING_ID(([UPC]),([Description]))
    it has two columns UPC and Description so bit mask will be as follows
    0 ie 00 for rows grouped by both UPC and Description fields
    1 ie 01 for rows grouped by UPC ie UPC subtotals
    2 ie 10 for rows grouped by Description ie Description subtotals
    3 ie 11 for rows not grouped by both columns ie Grand total
    see
    http://msdn.microsoft.com/en-IN/library/bb510624.aspx
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • What is the best way to deal with memory leak issue in sql server 2008 R2

    What is the best way to deal with memory leak issue in sql server 2008 R2.

    What is the best way to deal with memory leak issue in sql server 2008 R2.
    I have heard of memory leak in OS that too because of some external application or rouge drivers SQL server 2008 R2 if patched to latest SP and CU ( may be if required) does not leaks memory.
    Are you in opinion that since SQL is taking lot of memory and then not releasing it is a memory leak.If so this is not a memory leak but default behavior .You need to set proper value for max server memory in sp_configure to limit buffer pool usage.However
    sql can take more memory from outside buffer pool if linked server ,CLR,extended stored procs XML are heavily utilized
    Any specific issue you are facing
    Please mark this reply as the answer or vote as helpful, as appropriate, to make it useful for other readers

  • Using upgrade advisor on a database with compatibility level 80 on SQL Server 2008

    Hi All,
    My DB compatibility level is 80 which is on SqL server 2008, however I want to upgrade the database server to sql 2014. 
    Now in my case the upgrade advisor of SQL 2014 is not detecting the DB which is in 80 compatibility level and hence I cannot proceed with the upgrade (as I do not want to rollback). 
    So what exactly  can I do in this situation? any help would be appreciated
    aa

    What Olaf said Or if possible change compatibility level of database to 100 and try. I guess since you want to upgrade there wont be any issue in changing. Well if anything happens you can safely change it back to 80
    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 Article
    MVP

  • Why i can not use dbco to connect sql server 2008?

    Dear Experts,
        i use this mehtod to link sql server 2005 :MSSQL_SERVER=tcp:mysqlserver IP  MSSQL_DBNAME=SubConPayment,
    it is ok,when i use this method to link sql server 2008 with dbco,it is not ok,can you tell me why i can not link to sql server2008 in sap with dbco?
    looking forward to your reply.
    Best regards,
    Merry

    Hi Merry,
    Seems that you have to add the "provider" attribute to the connectionstring. Please have a look at the following link: [http://www.connectionstrings.com/sql-server-2008#p2]
    Regards,
    Ozcan.

  • Unable to Load CSV file with comma inside the column(Sql Server 2008)

    Hi,
    I am not able load an CSV file with Comma inside a column. 
    Here is sample File:(First row contain the column names)
    _id,qp,c
    "1","[ ""0"", ""0"", ""0"" ]","helloworld"
    "1","[ ""0"", ""0"", ""0"" ]","helloworld"
    When i specify the Text Qualifier as "(Double quotes) it work in SQL Server 2012, where as fail in the SQL Server 2008, complaining with error:
    TITLE: Microsoft Visual Studio
    The preview sample contains embedded text qualifiers ("). The flat file parser does not support embedding text qualifiers in data. Parsing columns that contain data with text qualifiers will fail at run time.
    BUTTONS:
    OK
    I need to do this in sql server 2008 R2 with Service pack 2, my build version is 10.50.1600.1.
    Can someone let me know it is possible in do the same way it is handle in SQL Server 2012?
    Or
    It got resolved in any successive Cumulative update after 10.50.1600.1?
    Regards Harsh

    Hello,
    If you have CSV with double quotes inside double quotes and with SSIS 2008, I suggest:
    in your data flow you use a script transformation component as Source, then define the ouput columns id signed int, Gp unicode string and C unicode string. e.g. Ouput 0 output colmuns
    Id - four-byte signed
    gp - unicode string
    cc - unicode string
    Do not use a flat file connection, but use a user variable in which you store the name of the flat file (this could be inside a for each file loop).
    The user variable is supplied as a a readonly variable argument to the script component in your dataflow.
    In the script component inMain.CreateNewOutputRows use a System.IO.Streamreader with the user variable name to read the file and use the outputbuffer addrow method to add each line to the output of the script component.
    Between the ReadLine instraction and the addrow instruction you have to add your code to extract the 3 column values.
    public override void CreateNewOutputRows()
    Add rows by calling the AddRow method on the member variable named "<Output Name>Buffer".
    For example, call MyOutputBuffer.AddRow() if your output was named "MyOutput".
    string line;
    System.IO.StreamReader file = new System.IO.StreamReader( Variables.CsvFilename);
    while ((line = file.ReadLine()) != null)
    System.Windows.Forms.MessageBox.Show(line);
    if (line.StartsWith("_id,qp,c") != true) //skip header line
    Output0Buffer.AddRow();
    string[] mydata = Yourlineconversionher(line);
    Output0Buffer.Id = Convert.ToInt32(mydata[0]);
    Output0Buffer.gp = mydata[1];
    Output0Buffer.cc = mydata[2];
    file.Close();
    Jan D'Hondt - SQL server BI development

  • Creating New db(with new name) with the old db backup sql server 2008

    Friends..
    version: Sql Server 2008
    I have a database in a name college1 (more than 200 tables and view etc...)
    i want to create a new db with all the structures including the data of the above db college1 with a new name college2
    so...i finished the step 1 successfully.. what are the other steps i have to do...like validating the invalid objects. etc....
    Step 1:
    RESTORE DATABASE college2 FROM DISK = 'D:\DailyDBbackup\college1.bak'
      WITH replace,
      move 'college2 ' TO 'D:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\college2 .mdf',
      move  'college2 _log' TO 'D:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\college2 _log.ldf';
    step 2: ?
    Step 3: ?
    thanks...

    but...when i type
    use college1
    select * from (it will display all tables under the above db)
    but when i do..
    use college2
    select * from (only system tables are displaying..)
    Did restore completed successfully ? If yes Expand database , can you see tables in the new database you restored ?. Sometimes when you type incorrect word which does not matches anything you wont get help from intellicense you should not be worried about this
    if tables are there in new database college 2
    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 Article
    MVP

  • 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

  • How to use update trigger in sql server 2008 with specific column

    Hello friends currently my trigger updates on table update, and I need to change this to only fire when specific column changes.
    /****** Object: Table [dbo].[User_Detail] ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE TABLE [dbo].[User_Detail](
    [sno] [int] IDENTITY(1,1) NOT NULL,
    [userid] [nvarchar](50) NULL,
    [name] [nvarchar](max) NULL,
    [jointype] [nvarchar](50) NULL,
    [joinside] [nvarchar](50) NULL,
    [lleg] [nvarchar](50) NULL,
    [rleg] [nvarchar](50) NULL,
    [ljoining] [int] NULL,
    [rjoining] [int] NULL,
    [pair] [int] NULL
    ) ON [PRIMARY]
    GO
    /****** Object: Table [dbo].[User_Detail] table data ******/
    SET IDENTITY_INSERT [dbo].[User_Detail] ON
    INSERT [dbo].[User_Detail] values (1, N'LDS', N'LDS Rajput', N'free', N'Left', N'jyoti123', N'SUNIL', 6, 4, 4)
    INSERT [dbo].[User_Detail] VALUES (2, N'jyoti123', N'jyoti rajput', N'free', N'Left', N'mhesh123', N'priya123', 3, 2, 2)
    SET IDENTITY_INSERT [dbo].[User_Detail] OFF
    /****** Object: Table [dbo].[User_Detail] trigger ******/
    CREATE TRIGGER triggAfterUpdate ON User_Detail
    FOR UPDATE
    AS
    declare @userid nvarchar(50);
    declare @pair varchar(100);
    select @userid=i.userid from inserted i;
    select @pair=i.pair from inserted i;
    SET NOCOUNT ON
    if update(pair)
    begin
    insert into Complete_Pairs(userid,pair)
    values(@userid,1);
    end
    GO
    /****** Object: Table [dbo].[Complete_Pairs] Script Date: 05/22/2014 21:20:35 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE TABLE [dbo].[Complete_Pairs](
    [Sno] [int] IDENTITY(1,1) NOT NULL,
    [userid] [nvarchar](50) NULL,
    [pair] [int] NULL
    ) ON [PRIMARY]
    GO
    my query is TRIGGER triggAfterUpdate is fired only when pair column in User_Details table is update only and when we update other column like ljoin or rjoin then my trigger is not fired
    please any one can suggest us how it can done or provide solution
    Jitendra Kumar Sr. Software Developer at Ruvixo Technologies 7895253402

    >select @userid=i.userid
    frominserted i;
            select
    @pair=i.pair
    frominserted i;
    The code above assumes a single row UPDATE.
    You have to setup the trigger for set processing like when 100 rows are updated in a single statement.
    UPDATE trigger example: http://www.sqlusa.com/bestpractices2005/timestamptrigger/
    Kalman Toth Database & OLAP Architect
    SQL Server 2014 Design & Programming
    New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012

  • Is it possible to assign an AD User to SQL Server Login with a defined set of SQL Server Roles?

    A customer asked me if its possible to define in the Active Directory, the SQL Server Roles that should be automatically assigned to a sql server Login that is mapped to a Windows Account.
    In short, his idea is:
    - he creates in the Active Directory a User Group that "knows" about the SQL Server "SecutityAdmin" role
    - some Windows Windows Accounts are Member of this AD Group
    - if one of this Windows Domain Account is mapped to a SQL Server Login "CREATE LOGIN [<domainName>\<login_name>] FROM WINDOWS;" the created SQL Server Login will automatically be a Member of the SQL Server SecurityAdmin.
    Do you know if its possible to configure the AD / SQL Server in this manner?
    I invested some time searching through SQL Server Onlinehelp and AD Documentation. Found nothing. Dont even know if its fiction or a realistic wish.
    Any help, hint, adivce is really appreciated.
    Best Regards
    Paolo

    Yes, you can create an AD Group named "SQLSecurityAdmins", assign a login in SQL Server to this group and grant SecurityAdmin role to it (exec sp_addsrvrolemember).
    Bodo Michael Danitz - MCT, MCITP - free consultant - performance specialist - www.sql-server.de
    Hi Bodo
    Thank you very much for your reply. Dont know if i got it right.
    I create the AD Group "SQLSecurityAdmin", assign it to SQL Server Login and manually add the SQL Server Login as a Member of the SQL Server "SecurityAdmin" Role.
    Now i have a new AD User "NewUser", make him a member of the AD Group "SQLSecurityAdmin". Then i execute "CREATE LOGIN [DomainName\NewUser] FROM WINDOWS;". Is now the new SQL Login Mapped to the Windows Account "DomainName\NewUser" automatically member of
    the SQL Server SecurityAdmin Group?
    Best Regards
    Paolo

  • TSQL Query to display First and Last Values of a GROUP as Columns - SQL Server 2008

    Could someone please help with the TSQL to achieve the following: Every Employee has 2 records (From & To). Output has to display one record for each employee with From & To as columns.
    Input
    Empid
    Type
    Date
    100
    From
    5/4/2004
    100
    To
    6/2/2008
    101
    From
    6/12/2003
    101
    To
    6/2/2013
    102
    From
    12/12/2012
    102
    To
    5/3/2014
    Output
    EmpID
    From
    To
    100
    5/4/2004
    6/2/2008
    101
    6/12/2003
    6/2/2013
    102
    12/12/2012
    5/3/2014
    Thanks, Ashish Singh

    SELECT empid,
    MAX(CASE WHEN Type='From' THEN date END) from,
    MAX(CASE WHEN Type='To' THEN date END) to
    FROM tbl GROUP BY empid
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Sum a field without using field in group by statement- sql server 2008 SSRS

    I am trying to write a query as follows;
    select todate, sum(entries) as A, sum(entries) as B  *(where dept=HR)
    from table 1
    where dept in(IT,HR)
    group by todate
    here A is summation of all the entries for dept IT and HR
    and want to get B as summation of entries having dept HR only
    Kindly note this sql would be used in ssrs 2008 dataset query.
    Please help.
    Thanks

    Hi, you can write it like this:
    select todate, sum(entries) as A, SUM(CASE WHEN Dept = 'HR' THEN entries ELSE 0 END) as B
    from table 1
    where dept in('IT','HR')
    group by todate
    Martina White

  • (new?) performance problem using jDriver after a Sql Server 6.5 to 2000 conversion

    Hi,
    This is similar - yet different - to a few of the old postings about performance
    problems with using jdbc drivers against Sql Server 7 & 2000.
    Here's the situation:
    I am running a standalone java application on a Solaris box using BEA's jdbc driver
    to connect to a Sql Server database on another network. The application retrieves
    data from the database through joins on several tables for approximately 40,000
    unique ids. It then processes all of this data and produces a file. We tuned
    the app so that the execution time for a single run through the application was
    24 minutes running against Sql Server 6.5 with BEA's jdbc driver. After performing
    a DBMS conversion to upgrade it to Sql Server 2000 I switched the jDriver to the
    Sql Server 2000 version. I ran the app and got an alarming execution time of
    5hrs 32 min. After some research, I found the problem with unicode and nvarchar/varchar
    and set the "useVarChars" property to "true" on the driver. The execution time
    for a single run through the application is now 56 minutes.
    56 minutes compared to 5 1/2 hrs is an amazing improvement. However, it is still
    over twice the execution time that I was seeing against the 6.5 database. Theoretically,
    I should be able to switch out my jdbc driver and the DBMS conversion should be
    invisible to my application. That would also mean that I should be seeing the
    same execution times with both versions of the DBMS. Has anybody else seen a
    simlar situation? Are there any other settings or fixes that I can put into place
    to get my performance back down to what I was seeing with 6.5? I would rather
    not have to go through and perform another round of performance tuning after having
    already done this when the app was originally built.
    thanks,
    mike

    Mike wrote:
    Joe,
    This was actually my next step. I replaced the BEA driver with
    the MS driver and let it run through with out making any
    configuration changes, just to see what happened. I got an
    execution time of about 7 1/2 hrs (which was shocking). So,
    (comparing apples to apples) while leaving the default unicode
    property on, BEA ran faster than MS, 5 1/2 hrs to 7 1/2 hrs.
    I then set the 'SendStringParametersAsUnicode' to 'false' on the
    MS driver and ran another test. This time the application
    executed in just over 24 minutes. The actual runtime was 24 min
    16 sec, which is still ever so slightly above the actual runtime
    against SS 6.5 which was 23 min 35 sec, but is twice as fast as the
    56 minutes that BEA's driver was giving me.
    I think that this is very interesting. I checked to make sure that
    there were no outside factors that may have been influencing the
    runtimes in either case, and there were none. Just to make sure,
    I ran each driver again and got the same results. It sounds like
    there are no known issues regarding this?
    We have people looking into things on the DBMS side and I'm still
    looking into things on my end, but so far none of us have found
    anything. We'd like to continue using BEA's driver for the
    support and the fact that we use Weblogic Server for all of our
    online applications, but this new data might mean that I have to
    switch drivers for this particular application.Thanks. No, there is no known issue, and if you put a packet sniffer
    between the client and DBMS, you will probably not see any appreciable
    difference in the content of the SQL sent be either driver. My suspicion is
    that it involves the historical backward compatibility built in to the DBMS.
    It must still handle several iterations of older applications, speaking obsolete
    versions of the DBMS protocol, and expecting different DBMS behavior!
    Our driver presents itself as a SQL7-level application, and may well be treated
    differently than a newer one. This may include different query processing.
    Because our driver is deprecated, it is unlikely that it will be changed in
    future. We will certainly support you using the MS driver, and if you look
    in the MS JDBC newsgroup, you'll see more answers from BEA folks than
    from MS people!
    Joe
    >
    >
    Mike
    The next test you should do, to isolate the issue, is to try another
    JDBC driver.
    MS provides a type-4 driver now, for free. If it is significantly faster,
    it would be
    interesting. However, it would still not isolate the problem, because
    we still would
    need to know what query plan is created by the DBMS, and why.
    Joe Weinstein at BEA
    PS: I can only tell you that our driver has not changed in it's semantic
    function.
    It essentially send SQL to the DBMS. It doesn't alter it.

  • Distributed transaction using linked server not working in SQL Server 2008 64 bit

    Hi. I have had an issue trying to get distributed transactions to work in SQL Server 2008 using a linked server. The error message I get is
    OLE DB provider "SQLNCLI10" for linked server "pod1" returned message "No transaction is active.".
    Msg 7391, Level 16, State 2, Line 3
    The operation could not be performed because OLE DB provider "SQLNCLI10" for linked server "pod1" was unable to begin a distributed transaction.
    My Environment:
    Windows Server 2008 Enterprise 64 bit, SQL Server 2008 Enterprise 64 bit
    Problem occurs with multiple different builds of SQL Server 2008 - I have been able to reproduce the problem with 10.0.1600.0, 10.0.1779.0 (CU 2), as well as 10.0.2531 (SP1)
    I am aware that other people have had this issue and have reviewed all existing posts. I have verified that the MSDTC is configured correctly on both machines. I have also used DTCTester to verify that DTC is working correctly on all machines in question.
    None of the mentioned resolutions has solved this problem for me.
    I am not seeing this problem occur on my 32 bit test machines - it is only occurring if at least one of the two machines is 64 bit.

    Hi All,
    I realise that this topic may be a little bit out-of-date but if someone gets here from some search engine trying to find a solution for DTC problems, this MAY be useful.
    So... I recently had the same issue, tried all the approaches described in KB and other articles, but it didn't help. Because my task to solve this was not of the highest priority I forgot about it for some time.
    Today I was troubleshooting some other issue and, by accident discovered source of that first problem:
    In the EventViewer I found Error entry logged by MSDTC saying:
    "The local MS DTC detected that the MS DTC on vm-server1 (other machine name that also runs DTC - my comment) has the same unique identity as the local MS DTC. This means that the two MS DTC will not be able to communicate
    with each other. This problem typically occurs if one of the systems were cloned using unsupported cloning tools. MS DTC requires that the systems be cloned using supported cloning tools such as SYSPREP. Running 'msdtc -uninstall' and then 'msdtc -install'
    from the command prompt will fix the problem. Note: Running 'msdtc -uninstall' will result in the system losing all MS DTC configuration information."
    So I followed suggestion and run:
    msdtc -uninstall
    msdtc -install
    This solved my problems with DTC. Hope it will help someone.
    Piotr

  • Problem with full backup with copy only in maintenance plan sql server 2008

    Hello
    I am starter DBA for sql server in general
    I have problem related to backup with maintenance plan in sql server 2008 and 2008 r2
    I created maintenance plan to take full back up  with copy only option checked, but when I check the back up in backupset table is_copy_only column it shows 0 for databases that I run job for.
    I did the same steps on sql server 2012 and I checked backupset table is_copy_only column it shows 1 for databases that I run job for .so it works as it should be
    Note: all the servers I mention here are production servers 

    Copy-only Backup  by using GUI ( SSMS) in SQL Server 2008 but it was not available in  Maintenance Plan "Back
    Up Database Task". Now in SQL Server 2012 It is included in "Back Up Database
    Task". 
    http://sqlage.blogspot.in/2013/06/dba-maintenance-plan-back-up-database.html

Maybe you are looking for

  • Print html report with waveform

    I'm trying to make a report on my system using print from the File menu, and then saving the report as a html document. However, I don't seem to get the descriptions for waveforms in the report. I've tried on both WIN-NT and WIN-2000 machines, but st

  • How do i make my Video look like a dream.

    Hi, I was doing a cartoon video thing. And There should be this person Dreaming about stuff. Usually in Tv shows, Dreams are Black and While + a smooshy black frame thing. I know how to do the Ones where i make a frame that looks like a box. But it l

  • While filling setup table

    hi, whilw iam filling setup table iam getting the error    <b>No extraction structure active or no BW</b> in rsa5 and rsa6 i did the procedure inlbwe that ds is active i deleted the set uptable after i fill the set up table iam getting this error iam

  • Why can't I open news articles on Yahoo using FireFox? I can open them using a different browser but get an error message when trying to use FireFox. The message is 400 bad request.

    Sorry, Bad Request. Your browser sent a request that this server could not understand. Size of a request header field exceeds server limit. Cookie: B=75kpq496lk13o&b=4&d=sCtogappYEIRcz6KBGzeoYZ9MqTV.a4yAp6fAQ--&s=ka&i=KBG0.9m3_RKQtWi41uCH; CH=Ahs0Zxv

  • Wired Mighty Mouse problems

    Over the last week I've been experiencing some very frustrating problems with the wired Might Mouse running on my Dual 2.0Ghz PowerMac G5 (10.4.9). I've tried cleaning it with compressed air and the consistent problems would indicate that it's not a