Null behaviour on SQL 2008

Sorry guys, is there anyone who can explain me the null behaviour on SQL 2008? I mean, I got this select
select customername, contract, CONVERT(varchar(6),settlementdate,112) as per, sum(consumption) as
weight, SUM(gp2) as gp, SUM(tot) as abp, SUM(ccost) as ccost,  
from big15 group by customername, contract, CONVERT(varchar(6),settlementdate,112)                                                                                                                               
That retrieves me
Warning: Null value is eliminated by an aggregate or other SET operation.
(22118 row(s) affected)
Now I'm wondering, what means? That it has considered the null as zero value? Or that it has truncate or dropped the rows cointaning a null value? It's something I lost in my brain.
And in this case:
select customername, contractid, CONVERT(varchar(6),settlementdate,112) as per,   gp,  abp,  ccost,  RcCost,
(gp + abp + ccost + rccost) as tot                 
That return null if there is a null value. Now
I am going to try Isnull or Coalesce but what concern me is the first question. In a sum column what is the rule on SQL. Zero or drop ( don't consider) the row?

>>>Warning: Null value is eliminated by an aggregate or other SET operation.
You have SUM aggregation function which returns NULL for some data....(you may have COALESCE function to handle the NULLs)
>>>(gp + abp + ccost + rccost) as tot  
Again use (coalesce(gp,0)
+ coalesce(abp,0) + coalesce(ccost,0) + coalesce(rccost,0)) as tot  
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

Similar Messages

  • Update Upper row column value in null column in sql 2008

    Hi All,
    I want to update Upper row value into lower null value column dynamically . i have 10000 record .
    any one have  sql query or any idea.Please help 
    Akhilesh Sahu Sr.Software Developer

    Hi akhilesh,
    Based on your description, you want to Sorting by a specified order that NULL value should be located in the bottom of some columns. If in this scenario, we can try to add a calculated field to convert the values of the field to A, B depend on the specified
    order. Then Sorting the field by A to Z to achieve your requirement. For more details, please refer to the following steps:
    Right-click the dataset to add a calculated field named Order with the expression like below:
    =iiF(Fields!CircleId.Value="","B","A")
    Right-click the report item to open the properties dialog box.
    Click Sorting in the left pane, then add a sorting as below:
    Sort by: [Order]                                                           
    Order: A to Z
    If you have any other questions, please feel free to let me know.
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • Calling a stored procedure on SQL 2008 server

    This might be easy one, but I tried different things just cannot get it to work.
    I am trying to call a stored procedure in SQL 2008 R2 server using Type 4 driver (sqljdbc4.jar) with JR.
    The stored procedure basically has one input and two outputs
    ALTER PROCEDURE [dbo].[usp_Example_Master]
    @XMLResponse as varchar(max),
    @ERROR_NUMBER as int OUTPUT,
    @ERROR_MESSAGE as varchar(300) OUTPUT
    as
    My program.
    Connection connection =null
    CallableStatement cs =null;
    connection = DriverManager.getConnection(url, username, password);
    cs = connection.prepareCall("{call dbo.usp_Example_Master(?,?,?)}");
    cs.setString(1,requestStr);
    cs.registerOutParameter(2, Types.INTEGER);
    cs.registerOutParameter(3, Types.VARCHAR);
    cs.execute();
    ============
    Error: The output parameter 1 was not registered for output.
    But if I added cs.registerOutParameter(1, Types.VARCHAR);
    Error: The formal parameter "@XMLResponse" was not declared as an OUTPUT parameter, but the actual parameter passed in requested output
    ==========
    Appreciate any help !

    Ok. I have an alternative to get it to work now.
    Instead of using index number, I am using the parameter name now. It works as expected and more intuitive any way.
    Ex.
    cs.setString("XMLResponse",req);
    cs.registerOutParameter("ERROR_NUMER",Type.INTEGER);
    Edited by: 903857 on Dec 21, 2011 2:45 PM

  • SQL 2008 Problem Calling an SP on an Oracle 10G Linked Server

    Hi everyone
    I've read through a number of posts on many sites about this issue but haven't found anything that has helped me so far. The machine I'm using is running Microsoft SQL Server 2008 64bit and the linked server I've created to Oracle 10G is using OraOLEDB.Oracle. If I test the connection in SQL Management Studio it succeeds and for any queries I have using OpenQuery to select from the Oracle DB I have no problem getting results.
    The Oracle 32bit client and 64bit client versions are installed on the machine.
    My problem is that I need to exec an Oracle SP which in turn inserts into various Oracle tables. I previously had this all working fine on 32bit SQL Server 2000 installation connected to Oracle 10G. Using the same code in SQL Server 2008 I get the following error:
    Msg 7357, Level 16, State 2, Line 1
    Cannot process the object "{CALL INTF.INTF_TW_PO_REQ_INTERFACE.MAIN(NULL, 15.000000, 0.000000, 'BLPO0099998', 'BLPO0099998', '', '', 39804, 21883, 'BLPO0099998', 249, 1, 950, 'Main', 190506, 37336, '1', TO_DATE( '20090706','YYYYMMDD' ), TO_DATE( '20090706','YYYYMMDD' ), 'INCOMPLETE',37336, {RESULTSET 1, P_Success})}". The OLE DB provider "OraOLEDB.Oracle" for linked server "ORACLE" indicates that either the object has no columns or the current user does not have permissions on that object
    The call is made by the following piece of code in SQL:
    SET @execCmd = N'SELECT
    P_Success
    FROM
    OPENQUERY( ORACLE, '''+ @oracleCmd + ''')';
    EXECUTE (@execCmd);
    Where @oracleCmd = {CALL INTF.INTF_TW_PO_REQ_INTERFACE.MAIN(NULL, 15.000000, 0.000000, ''BLPO0099998'', ''BLPO0099998'', '''', '''', 39804, 21883, ''BLPO0099998'', 249, 1, 950, ''Main'', 190506, 37336, ''1'', TO_DATE( ''20090706'',''YYYYMMDD'' ), TO_DATE( ''20090706'',''YYYYMMDD'' ), ''INCOMPLETE'',37336, {RESULTSET 1, P_Success})}
    I also tried using the below snippet from another post I found and got no joy either.
    declare @result varchar(255)
    exec ('BEGIN
    ?:= your_SP_Name(''arg1'', ''arg2'', etc);
    END;
    ',@result OUTPUT) at your_LinkedServerName;
    select @result;
    OLE DB provider "OraOLEDB.Oracle" for linked server "ORACLE" returned message "ORA-06550: line 3, column 7:
    PLS-00222: no function with name 'INTF_TW_PO_REQ_INTERFACE' exists in this scope
    ORA-06550: line 3, column 1:
    PL/SQL: Statement ignored".
    I can't figure out why it doesn't work in SQL 2008 when it worked fine in SQL 2000 - PLEASE HELP!
    Thank you
    Alida Hope

    Why development on 10g and production on 8i? Either both should be 8i or both should be 10g.
    If you will keep production on 8i and development on 10g then you cannot stop such errors as there are features that are enabled by default in 10g and both the versions have very big differences.
    Just go ahead and install 8i.

  • Server0 starts very slowly in PI 7.11 in Win 2008 / SQL 2008 MSCS config

    Hi all.
    I have a problem in our newly installed PI 7.11 system on Windows Server 2008 and MS SQL 2008 MSCS setup. The J2EE application server on the node where the SCS is running, takes about 1 hour to start. About 20 minutes after starting, it goes from starting framework to starting apps, and then remains in that status for another 40-50 minutes. I am unable to find anything in the log files that can explain this behaviour. The J2EE app server on the second cluster nodes starts within 5-6 minutes. If I fail over the SAP Cluster Group to the second node, the situation is reversed.
    We are using the latest 7.11 kernel and the latest available SPS.
    Has anyone experiences something similar?
    Regards,
    Thomas

    Hi.
    Thanks for your input!
    I found this document [Process Integration (PI) Performance Check - Analyzing Performance Problems and Possible Solution Strategies|http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/f0b96675-87cf-2c10-b489-dee0ac03f782?quicklink=index&overridelayout=true].
    I also remembered having read somewhere that the VMC should be turned off for PI. So I set the parameter vmcj/enable = off. If this really did the trick or not, I cannot guarantee, but now my server0 processes starts normally.
    Regards,
    Thomas

  • Error mapping, OGG from SQL 2008 to Oracle 11g

    Hi Experts
    Please I hoppe you can help me, I am using OGG to replicate from SQL 2008 to Oracle 11g R2, I can insert rows and replicate without problems, but when I update or delete on the Source the replicat stop working.
    This is the mesage:
    2012-06-11 09:51:57 ERROR OGG-01296 Oracle GoldenGate Delivery for Oracle, msrep.prm: Error mapping from FACTURA.EMP to GOLDENGATE.EMP.
    2012-06-11 09:51:57 ERROR OGG-01668 Oracle GoldenGate Delivery for Oracle, msrep.prm: PROCESS ABENDING.
    --- Discard FIle
    Key column FIRST_NAME (1) is missing from delete on table GOLDENGATE.EMP
    Key column LAST_NAME (2) is missing from delete on table GOLDENGATE.EMP
    Missing 2 key columns in delete for table GOLDENGATE.EMP.
    Current time: 2012-06-11 09:51:57
    Discarded record from action ABEND on error 0
    Aborting transaction on /u01/app/goldenGate/dirdat/ms beginning at seqno 0 rba 13729
    error at seqno 0 rba 13729
    Problem replicating FACTURA.EMP to GOLDENGATE.EMP
    Mapping problem with delete record (target format)...
    ID = 121
    Process Abending : 2012-06-11 09:51:57
    ------ SOURCE TABLE
    create table [factura].[emp] (
    [id] [smallint] not null,
    [first_name] varchar(50) not null,
    [last_name] varchar(50) not null,
    constraint [emp_pk] primary key clustered (
    [id] asc
    ) with (pad_index = off, statistics_norecompute=off, ignore_dup_key=off, allow_row_locks=on, allow_page_locks=on) on [primary]
    ) on [primary]
    ------ TARGET TABLE
    CREATE TABLE GOLDENGATE.EMP
    ID NUMBER,
    FIRST_NAME VARCHAR2(50 BYTE),
    LAST_NAME VARCHAR2(50 BYTE)
    Thank you
    J.A.

    Hi
    I altered the table in Oracle, I add the primary key:
    alter table emp add constraint
    pk_emp primary key (ID );
    Now GG replicate insert, delete and update.
    J.A.

  • SQL query is slow after upgrading from SQL 2008 to SQL 2008 R2

    Hello
    We were using SQL 2008 Standard, but after upgrading to R2, following query is much slower (takes 5 seconds instead of less than 1 second), how is this possible?
    Regards, Hennie
    SELECT
     P.BSN,
     P.Persnr,
     P.Roepnaam,
     P.Tussenvoegsels,
     P.Achternaam,
     P.Geslacht,
     COALESCE (P.Achternaam + ', ' + P.Roepnaam + ' ' + P.Tussenvoegsels, P.Achternaam + ', ' + P.Roepnaam, P.Achternaam) AS naamvolledig,
     P.Telmobiel,
     P.Telvast,
     P.Postcode,
     G.groep,
     COALESCE (RM.nieuweDag, GR.Dag) AS dag,
     COALESCE (RM.nieuweDatum, GR.datum) AS datum,
     DATEPART(ww, COALESCE (RM.nieuweDatum, GR.datum)) AS weeknummer,
     DATEPART(yyyy, COALESCE (RM.nieuweDatum, GR.datum)) AS jaar,
     CONVERT(VARCHAR(8),
      CASE WHEN GR.ID_lokaties = 3 THEN COALESCE (RM.nieuweBegintijd,
       CASE WHEN GR.Tijdspan = 2 THEN R.begintijd2 ELSE R.begintijd END)
      ELSE COALESCE (RM.nieuweBegintijd, GR.begintijd) END, 108) AS begintijdberekend,
     CONVERT(VARCHAR(8),
      CASE WHEN GR.ID_lokaties = 3 THEN COALESCE (RM.nieuweEindtijd,
       CASE WHEN GR.Tijdspan = 2 THEN R.eindtijd2 ELSE R.eindtijd END)
      ELSE COALESCE (RM.nieuweEindtijd, GR.eindtijd) END, 108) AS eindtijdberekend,
     CASE WHEN GR.ID_lokaties = 3 THEN
       CONVERT(NCHAR(5), COALESCE (RM.nieuweBegintijd,CASE WHEN GR.Tijdspan = 2 THEN R.begintijd2 ELSE R.begintijd END), 108) + '-' +
       CONVERT(NCHAR(5), COALESCE (RM.nieuweEindtijd, CASE WHEN GR.Tijdspan = 2 THEN R.eindtijd2 ELSE R.eindtijd END), 108)
      ELSE CONVERT(NCHAR(5),COALESCE (RM.nieuweBegintijd, GR.begintijd), 108) + '-' + CONVERT(NCHAR(5), COALESCE (RM.nieuweEindtijd, GR.eindtijd), 108)
      END AS Tijdspanne,
     CASE
      WHEN GR.ID_lokaties = 3 AND R.id_relaties = 9 THEN 'Werk Intern'
      WHEN GR.ID_lokaties = 3 THEN R.relatienaam
      ELSE L.lokatie END AS Lokatieberekend,
     R.relatienaam AS relatie,
     L.IntExt,
     RA.Omschrijving AS roosteractiviteit,
     A.instroomdatum,
     A.uitstroomdatum,
     TT.trajecttype,
     W.Naamvolledig AS Werkcoach,
     A.ID_groepen,
     T.ID_personen,
     A.ID_werkcoaches,
     CASE
      WHEN GR.ID_lokaties = 3 AND R.id_relaties = 9 THEN 20
      WHEN GR.ID_lokaties = 3 THEN R.id_relaties
      ELSE L.ID_relaties END AS ID_lokatieberekend,
     A.ID_relaties AS ID_relatie,
     R.nummer2 AS capaciteit,
     GR.ID_groepsroosters,
     CAST(CASE WHEN foto IS NOT NULL THEN 'Ja' ELSE NULL END AS char(2)) AS Foto,
     W.Email,
     W.TelefoonMobiel,
     W.TelefoonVast
    FROM
     dbo.personen AS P INNER JOIN
     dbo.trajecten AS T ON T.ID_personen = P.ID_personen INNER JOIN
     dbo.trajecttype AS TT ON T.ID_trajecttype = TT.ID_trajecttype INNER JOIN
     dbo.trajectactiviteiten AS A ON A.ID_trajecten = T.ID_trajecten INNER JOIN
     dbo.groepsroosters AS GR ON GR.ID_groepen = A.ID_groepen LEFT OUTER JOIN
     dbo.roosteractiviteit AS RA ON GR.ID_roosteractiviteit = RA.ID_roosteractiviteit INNER JOIN
     dbo.lokaties AS L ON GR.ID_lokaties = L.ID_lokaties INNER JOIN
     dbo.werkcoaches AS W ON A.ID_werkcoaches = W.ID_werkcoaches INNER JOIN
     dbo.groepen AS G ON A.ID_groepen = G.ID_groepen LEFT OUTER JOIN
     dbo.relaties AS R ON A.ID_relaties = R.ID_relaties LEFT OUTER JOIN
     dbo.roostermutaties AS RM ON P.ID_personen = RM.ID_personen AND GR.ID_groepsroosters = RM.ID_groepsroosters AND RM.aanwezig IS NULL
    WHERE
     (COALESCE (RM.nieuweDatum, GR.datum) BETWEEN GETDATE() - 1 AND GETDATE() + 13)
     AND (COALESCE (DATEDIFF(day, COALESCE (RM.nieuweDatum, GR.datum), A.uitstroomdatum), 0) >= 0)
     AND (DATEDIFF(day, A.instroomdatum, COALESCE (RM.nieuweDatum, GR.datum)) >= 0)
     AND ((SELECT COUNT(*) AS Expr1
      FROM dbo.roostermutaties AS RM2
      WHERE (P.ID_personen = ID_personen)
      AND (GR.ID_groepsroosters = ID_groepsroosters)
      AND (CONVERT(VARCHAR(8), begintijdafwezig, 108) = CONVERT(VARCHAR(8),
      CASE WHEN GR.ID_lokaties = 3 THEN COALESCE (RM.nieuweBegintijd,
      CASE WHEN GR.Tijdspan = 2 THEN R.begintijd2 ELSE R.begintijd END)
      ELSE COALESCE (RM.nieuweBegintijd, GR.begintijd) END, 108)) AND
      (CONVERT(VARCHAR(8), eindtijdafwezig, 108) = CONVERT(VARCHAR(8), CASE WHEN GR.ID_lokaties = 3 THEN COALESCE (RM.nieuweEindtijd,
      CASE WHEN GR.Tijdspan = 2 THEN R.eindtijd2 ELSE R.eindtijd END) ELSE COALESCE (RM.nieuweEindtijd, GR.eindtijd) END, 108))) = 0)

    We were using SQL 2008 Standard, but after upgrading to R2, following query is much slower (takes 5 seconds instead of less than 1 second), how is this possible?
    It is not uncommon to experience performance problems following an upgrade when there are issues with original query.  Non-sargable expressions like Olaf called out are often the culprit, as well as lack of useful indexes and statistics. 
    The optimizer cannot glean accurate row count estimates or use indexes efficiently so the resultant plan may not be optimal for the task at hand.  It is only by happenstance that old plan performed better; it could just as well be the other way around,
    but again only by chance since the optimizer is guessing.
    You might also try using EXISTS instead of SELECT COUNT(*)...= 0:
    AND EXISTS(SELECT *
    FROM dbo.roostermutaties AS RM2
    WHERE P.ID_personen = ID_personen
    AND GR.ID_groepsroosters = ID_groepsroosters
    AND CONVERT(VARCHAR(8), begintijdafwezig, 108) = CONVERT(VARCHAR(8),
    CASE WHEN GR.ID_lokaties = 3 THEN COALESCE (RM.nieuweBegintijd,
    CASE WHEN GR.Tijdspan = 2 THEN R.begintijd2 ELSE R.begintijd END)
    ELSE COALESCE (RM.nieuweBegintijd, GR.begintijd) END, 108)
    AND CONVERT(VARCHAR(8), eindtijdafwezig, 108) = CONVERT(VARCHAR(8), CASE WHEN GR.ID_lokaties = 3 THEN COALESCE (RM.nieuweEindtijd,
    CASE WHEN GR.Tijdspan = 2 THEN R.eindtijd2 ELSE R.eindtijd END) ELSE COALESCE (RM.nieuweEindtijd, GR.eindtijd) END, 108))
    Dan Guzman, SQL Server MVP, http://www.dbdelta.com

  • SQL 2008 R2 Export to Excel 2007

    I want to export data using the Import and Export Utility to Excel 2007.  
    I choose a destination of Microsoft Excel and choose an existing (empty) Excel 2007 .xlsx file. 
    The following errors result.  A new worksheet is created in the Excel file with the name of the table and with column headings but no data.  If I repeat the export choosing the now existing Excel file it works fine.
    How can I make it work the first time?
    - Pre-execute (Error)
    Messages
    Error 0xc0202009: Data Flow Task 1: SSIS Error Code DTS_E_OLEDBERROR.  An OLE DB error has occurred. Error code: 0x80040E21.  (SQL Server Import and Export
    Wizard)  
    Error 0xc0202025: Data Flow Task 1: Cannot create an OLE DB accessor. Verify that the column metadata is valid.  (SQL Server Import and Export Wizard)  
    Error 0xc004701a: Data Flow Task 1: component "Destination - RELEASE_LOG" (58) failed the pre-execute phase and returned error code 0xC0202025.  (SQL
    Server Import and Export Wizard)  
    - Executing (Warning)
    Messages
    Warning: Preparation SQL Task 1: Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done. (SQL Server Import
    and Export Wizard)  
    Warning: Preparation SQL Task 1: Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done. (SQL Server Import
    and Export Wizard)  

    Thanks for your reply.
    I think the datatypes are correct.  
    This is the sql for the SQL 2008 table:
    CREATE TABLE [dbo].[q_table](
    [Q_No] [nvarchar](40) NOT NULL,
    [data1] [nvarchar](255) NULL,
    [data2] [nvarchar](255) NULL
    ) ON [PRIMARY]
    This is the sql for the Excel table create.
    CREATE TABLE `q_table` (
    `Q_No` LongText,
    `data1` LongText,
    `data2` LongText
    There is only one row in the table:
    Q_No data1
    data2
    2 444 aaa
    The same export works fine if I select .xls (Excel 1997-2003).  This error happens with every table I try to export to .xlsx.  I created this table and export to try to debug the issue.
    We do this sort of export all the time and I want to use 2007 becuase we often have more than 65K rows to export.  Now we export to Access and then export to Excel but it adds time to the job.

  • EVDRE error after adding new member - AFTER installing SQL 2008 R2 SP1 CU2

    Hi guys.
    We're seeing the same error as detailed in Link:[Re: EVDRE error AFTER expanding on a newly added member, sometimes....;
    Basically, any new members that are added appear in the SQL tables, but throw out "EVDRE has encountered a problem..." when trying to use them.
    Generally, this problem clear up if we leave the member overnight (although why this should be, I have no idea - the system does nothing extra overnight).
    We have tried processing the cube, full processing of the application and even a server reboot, all to no avail.
    However, the generally accepted fix for this is to upgrade SQL 2008 R2 to SP1 CU2 (SQL 10.50.2772)
    This system was patched to that level before BPC was ever installed, precisely to avoid this problem.
    This is not the first time that we have seen this behaviour.
    I have experienced it in one other environment, which I keep meaning to rebuild.
    These installations are in completely different environments.  The only similarities are that they both use Windows Server 2008 R2 and SQL 2008 R2.
    The issue only started to appear in this second environment today (we have 3 other environments with the same software version that do not have the problem).
    It had been assumed before today that the first problematic environment might need a rebuild due to this issue being caused by some other factor.
    However, this is now far too coincidental to be the case.
    Has anyone seen similar issues even after patching to v10.50.2772, or does anyone have any suggestions at all.
    I could really do with a quick win on this one.
    Thanks

    Hi,
    i've had the same issue in the same days. I confirm that the issue appear after adding any member and it's clear overnight.
    My system is different:
    Windows Server 2008 NT 6.0 <X64> (Build 6002: Service Pack 2) Enterprise Edition
    and Microsoft SQL Server 2008 Enterprise Edition (SP1) - 10.0.2841.0 (X64)
    The issue appears in the last months.
    It's occurs only on specific machine (always the same client), in the same moment other machines can open the same input schedule and expand without problem.
    I've noted also that when I cancel the added member the issue disappear, the same behaviour with APShell.
    I have the same configuration on development and test environment, same version of O.S. and SQL server, but there I don't have problem. The only difference is that these two environments are single server (application and DB server on the same machine) Instead, the production environment is multiserver (2 application server + DB server).
    Maybe there is a service that take a long time for sincronization (it's triggered in the night?).
    Could you verify if on some machine the evdre works fine and and that when you delete the  added member evdre starts to work?
    Kind regards
    Roberto
    Edited by: Roberto Vidotti on Dec 19, 2011 6:01 PM

  • SQL 2008 R2 Unstable query

    Hello everyone,
    I have a query that selects no data but if fails when there's an order by clause or if there's a conversion of hardcoded date.
    The error looks like this: 
    This only happens when the table is indexed.
    I put a repro code below.
    Could you please let me know if the error reprodces itself in your environment and your thoughts why ?
    Thanks in advace.
    The code below reproduces the issue:
    CREATE TABLE [dbo].[Test](
    [ID] [varchar](20) NOT NULL,
    [DateStr] [varchar](20) NOT NULL,
    [status] [varchar](6) NOT NULL,
    ) ON [PRIMARY]
    GO
    CREATE NONCLUSTERED INDEX [IX_Test] ON [dbo].Test
    [ID] ASC
    --, [coverage] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    GO
    Insert Test
    ID
    , DateStr
    , status
    Values
    'policy number'
    , 'paid date'
    , 'status'
    -- This query fails
    select *
    , datepart(mm,Convert(datetime, '2015-03-24 23:59:00.000', 120))
    from Test
    where status = 'I'
    and convert(datetime,DateStr,103) < Convert(datetime, '2015-03-24 23:59:00.000', 120) --@curr_date--'2015-03-24 23:59:00.000'
    order by ID
    -- This query works
    select *
    --, datepart(mm,Convert(datetime, '2015-03-24 23:59:00.000', 120))
    from Test
    where status = 'I'
    and convert(datetime,DateStr,103) < Convert(datetime, '2015-03-24 23:59:00.000', 120) --@curr_date--'2015-03-24 23:59:00.000'
    order by ID
    -- This query also works
    select *
    , datepart(mm,Convert(datetime, '2015-03-24 23:59:00.000', 120))
    from Test
    where status = 'I'
    and convert(datetime,DateStr,103) < Convert(datetime, '2015-03-24 23:59:00.000', 120) --@curr_date--'2015-03-24 23:59:00.000'
    --order by ID
    -- If I drop the index all queries work
    Drop index Test.IX_Test
    Conversion failed when converting date and/or time from character string.
    SSIS question

    There is no guaranteed order of evaluation, so a query with a potential conversion error in it may succeed or fail depending on the query plan, phase of the moon etc. This also applies if the conversion is in the SELECT list, and the WHERE clause filters
    out the bad data. I'm not sure that I like the latter part, but that is just the way it works.
    The only way to filter out bad data in SQL 2008 is by using CASE:
    CASE WHEN isdate(col) = 1 THEN convert(datetime, col) ELSE NULL END
    This is needed both in the WHERE clause and in the SELECT list.
    It can be problematic if isdate returns 0, but the string converts according to the selected format code or vice versa.
    On SQL 2012 and later, because here you can use try_convert which returns NULL if the string does not convert.
    A general piece of advice is that you should not store dates or numbers in varchar columns. It is bound to cause misery and grief.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Least Cost Routing in SQL 2008

    Anybody tried stuff like least cost routing in sql 2008? I have a small road network represented by linestrings in sql, and I'd like to find the shortest (or any other) route between two points. Anyone have some links to whitepapers... tutorials maybe?

    I would like to perform routing in MS SQL 2012 which is going to be similar like pg routing ?
    Actually in pgrouting I'll do the following steps to create a routable network.
    1)
    create a database routing with template "template_routing"
    2)
    create table "road_network" with following constraints
    CHECK (st_ndims(the_geom) = 2)
    CHECK (geometrytype(the_geom) = 'MULTILINESTRING'::text OR the_geom IS NULL)
    CHECK (st_srid(the_geom) = 4030)
    Then
    -- @ CREATE INDEX FOR THE ROAD TABLE -------------------- IMPORTANT
    CREATE INDEX spatialindex_road
     ON road_network
     USING gist
     (the_geom);
    3)
    Perform following queries
    ALTER TABLE road_network ADD COLUMN "source" integer;
    ALTER TABLE road_network ADD COLUMN "target" integer;
    SELECT assign_vertex_id('road_network', 0.00001, 'the_geom', 'gid');
    CREATE INDEX source_idx ON road_network("source");
    CREATE INDEX target_idx ON road_network("target");
    ALTER TABLE road_network  ADD COLUMN length double precision;
    UPDATE road_network  SET length = length(the_geom);
    ALTER TABLE road_network  ADD COLUMN reverse_cost double precision;
    UPDATE road_network  SET reverse_cost = length;
    ALTER TABLE road_network  ADD COLUMN x1 double precision;
    ALTER TABLE road_network  ADD COLUMN y1 double precision;
    ALTER TABLE road_network  ADD COLUMN x2 double precision;
    ALTER TABLE road_network  ADD COLUMN y2 double precision;
    UPDATE road_network  SET x1 = x(ST_PointN(the_geom, 1));
    UPDATE road_network  SET y1 = y(ST_PointN(the_geom, 1));
    UPDATE road_network  SET x2 = x(ST_PointN(the_geom, ST_NumPoints(the_geom)));
    UPDATE road_network  SET y2 = y(ST_PointN(the_geom, ST_NumPoints(the_geom)));
    alter table road_network add column cost double precision default 0;
    update road_network set cost=0.1 where type='NH';
    update road_network set cost=0.2 where type='SH';
    update road_network set cost=0.3 where type='major';
    update road_network set cost=0.4 where type='minor';
    update road_network set cost=1.2 where type='colony';
    update road_network set cost=0.8 where type='third';
    4)
    Now network table created
    To check 
    Run: 
    run this query on ur postgreSQL....
    assign table name name and create a table
    CREATE TABLE shortest_path_astar_table_3(gid int4) with oids;
    SELECT AddGeometryColumn( 'shortest_path_astar_table_3', 'the_geom', 4030, 'MULTILINESTRING', 2 );
    INSERT INTO shortest_path_astar_table_3(the_geom) 
    SELECT the_geom FROM astar_sp_directed('road_network',37,43,true,true);
    Open "shortest_path_astar_table_3" on QGIS and check the path
    Is there any similar way to perform similar queries in SQL ?

  • Linked server issue using SQLNCLI versions on SQL 2008 & 2014

    Hi all,
    Our product creates databases on a sql server 2008 instance and creates linked servers between them to use distributed queries.
    This looks like: "EXEC sp_addlinkedserver 'linkDatabaseA', '', 'SQLNCLI10', '.', NULL, NULL, 'DatabaseA'"".
    Distributed queries from second database to DatabaseA work fine in this scenario.
    As we want to support both SQL 2008 and SQL 2014 in the next product version, I changed this to SQLNCLI11 as the provider
    and tested on SQL 2008 after installation of the SQLNCLI11 driver.
    This resulted in following error message:
    Msg 468, Level 16, State 9, Line 7
    Cannot resolve the collation conflict between "Latin1_General_CI_AS" and "SQL_Latin1_General_CP1_CI_AS" in the equal to operation.
    This is very suprising as the SQL Server 2008 instance and both DB's have "SQL_Latin1_General_CP1_CI_AS" as their collation sequence.
    Then I tried the opposite, installing SQLNCLI10 on SQL 2014. This gave exactly same error! Using SQLNCLI11 went fine ofcourse.
    Generation sp_addlinkedserver statements with correct driver based on SQL version, I'd rather not do (some of the calls are
    generated in SQL from settings in other db tables which are also used for external connx) and adding COLLATE to the queries also
    has consequences like performance degradation. Adding collate on SQL 2014 with SQLNCLI10 as linked server provider results in
    following error:
    Msg 7399, Level 16, State 1, Line 1617
    The OLE DB provider "SQLNCLI10" for linked server "linkDatabaseA" reported an error. Access denied.
    Msg 7301, Level 16, State 2, Line 1617
    Cannot obtain the required interface ("IID_IDBCreateCommand") from OLE DB provider "SQLNCLI10" for linked server "linkDatabaseA".
    Q: Is there any way that SQLNCLI11 can be made to work for linked servers on SQL2008 (preferred solution) or SQLNCLI10 on SQL2014?
    Thx for any feedback.
    Regards, Jouke

    Hi Sofiya,
    Thx for replying.
    For the deployment reasons  mentioned above, I would prefer to use only one SQLNCLI version in both 2008R2 & 2012/2014 scenario's. Most preferred would ofcourse be SQLNCLI11 as this is the latest.
    This would mean that I'd like to be able to configure linked server in SQL2008R2 using SQLNCLI11 driver.
    I would expect that it would be downward compatible with SQLNCLI10 for all client usage, including linked server, which in essence is one SQL DB doing client access to another SQL DB either on same server instance or another. I suspect it requests DB
    metadata from remote DB in order to make decisions and this seems not to work in my setup. If this metadata API is part of the public API, this could indicate that medadata API has been broken in SQLNCLI11 (heavy speculation on my part here!), which could
    also affect other usage (eg. linked server between SQL2008(R2) and SQL2012/2014 instances, (I'll try to set this up and test this, might take a few days. If someone is volunteering, below are db table schemes and query, update @datasrc to point to remote sql
    server instance)).
    Regards, Jouke
    -- This script to run on SQL2008(R2). On SQL2012/2014, install SQLNCLI10 and change @provider in sp_addlinkedserver call.
    -- Pre:
    --   - DatabaseA and DatabaseB are created manually in SSMS
    --   - SQLNCLI11 has been installed
    USE [DatabaseA]
    GO
    CREATE TABLE [dbo].[DatabaseATable](
     [IdField] [int] NOT NULL,
     [LinkField] [nchar](10) NULL,
     CONSTRAINT [PK_DatabaseATable] PRIMARY KEY CLUSTERED
     [IdField] ASC
    ) ON [PRIMARY]
    GO
    EXEC master.dbo.sp_addlinkedserver @server = N'linkDatabaseA', @srvproduct=N'',@provider=N'SQLNCLI11', @datasrc=N'.', @catalog=N'DatabaseA'
    GO
    USE [DatabaseB]
    GO
    CREATE TABLE [dbo].[DatabaseBTable](
     [IdField] [int] NOT NULL,
     [LinkField] [nchar](10) NULL,
     CONSTRAINT [PK_DatabaseBTable] PRIMARY KEY CLUSTERED
     [IdField] ASC
    ) ON [PRIMARY]
    GO
    SELECT b.*, a.*
    FROM DatabaseBTable AS b WITH(NOLOCK)
    JOIN linkDatabaseA.DatabaseA.dbo.DatabaseATable AS a
      ON a.LinkField = b.LinkField
    Hi Jouke Numan,
    According to your description, I install SQL Native Client 11.0 OLE DB Provider in SQL Server 2008R2, and as you post, create two database on the same instance with collation in server default, then create Linked Server with SQLNCI11.0.
     When I run the query statement, it can execute well. It also do not occur the collation conflict. I still recommend you check the collation of server, database, or column and so on.
    SQL Server Native Client 11.0 provides OLE DB support to applications connecting to SQL Server versions 2005, 2008, 2008R2, 2012. So for the deployment reasons, you can choose the only SQLNCLI11.0 in both SQL Server 2008R2 and SQL Server 2012/2014.
    Regards,
    Sofiya Li
    Sofiya Li
    TechNet Community Support

  • Cannot see new SQL 2008 R2 Express instance on Small Business Server 2011!

    Hi,
    As it is stated on the subject line, I'm having a problem after I did a new install of SQL 2008 R2 Express and put a new instance on SBS 2011.
    I'm developing a new program using SQL 2008 in C# and VB.Net. I have SQL 2008 R2 Express installed on my computer called "MSQL8R2EDATA" on my PC. Now I need to deploy it on SBS 2011 so I can do some testing on other workstations.
    I'm currently running Windows 7, 64 bit, and it's named STEVE-PC. The SBS 2011 is named SERVER1, and it's 64 bit as well.
    After installation on SERVER1 (SBS 2011), I then fired up SQL Server Configuration Manager and enabled Named Pipes, TCP/IP, and VIA.
    After I've completed the SQL Configuration on SERVER1, I went back on my PC (STEVE-PC) and I tried to use Management Studio to connect to the  new instance MSQL8R2EDATA on SBS 2011, only problem is, I only see the computer name, not the new instance
    I've installed.
    Back on SBS 2011 (SERVER1), I've verified that all the protocols are enabled, and the SQL Server Browser is automatically loaded and currently running, as well the MSQL8R2EDATA instance is automatically loaded and running, yet I still cannot see
    it from my PC (STEVE-PC). I even switched from dynamic ports to a static port of 64719 (that was what the MSQL8R2EDATA was listening on that port when it was dynamic), and then added new rules to the Windows Firewall for program of the SQLSERVR.EXE, and
    for UDP and TCP for port 64719 to "Allow All Connections" for Domain, Private, and Public; yet I still cannot connect SERVER1\MSQL8R2EDATA. I even disabled the firewall and then trying to connect once again to SBS 2001 and it still fails.
    In case you're wondering, I left it on port 64719 since there are other active SQL Servers on SBS 2011 (SharePoint, SBSMonitoring, and ACT7).
    Interestingly, when I run Management Studio on SBS 2011, I can see STEVE-PC\MSQL8R2EDATA and I'm able to log in and connect to it.
    So what's going on here?!? Why am I able to connect to STEVE-PC which is Windows 7 64 from SBS 2011 (SERVER1), but I cannot connect from my computer to that instance on SBS 2011??
    I really could use some big time help on this.
    EDIT: Sorry for the confusion, but on the Windows Firewall (WF.msc), I did add new rules for incoming connections on:
    Program incoming connections to SQLSERVR.EXE
    TCP Port 64719
    UDP Port 64719
    EDIT: To further assist, I have Management Studio installed on the SBS 2011, and I can locally log in and connect to the MSQL8R2DATA on SERVER1 with success. I even tried tcp:SERVER1\MSQL8R2DATA and again it is successful log-in and connection.
    Thanks in advance!
    Steve

    Hi,
    Thanks for the response, but I have a question:
    Installing SQL Express or SQL Server is not recommended on SBS
    2011 because it is a DC, however technically it will work.
    I'm a newbie when it comes to SBS 2011 and I'm taking a crash course on the subject. Can you explain to me what you mean by "DC"? Also, why
    isn't recommended to install a new instance on SBS 2011?
    As I also stated, I've added "New Rules" to the Windows Firewall to allow incoming connections on port 64719 for both TCP and UDP, and I also allowed incoming connections for SQLSERVR.EXE but no joy to connect to the SERVER1\MSQL8R2EDATA.
    And yes, I can log-in and connect locally on SERVER1 using Management Studio with success. I even used tcp:SERVER1\MSQL8R2EDATA with the same success. It's my workstation STEVE-PC that fails. If that fails, then the rest of the workstations are going to fail.
    Are you suggesting that I put the SQL Server 2008 Express on another workstation and just allow to to be
    accessed that way?

  • Issue With Report Builder After Installing SP3 for SQL 2008 R2

    Hello.  We are experiencing an issue with Report Builder 3.0 since installing SP3 for SQL 2008 R2 over the weekend.  You can no longer launch Report Builder from the Reporting Services URL (http://dicomweb/ReportServer/ReportBuilder/ReportBuilder_3_0_0_0.application
          Server  : Microsoft-HTTPAPI/2.0
          X-AspNet-Version: 2.0.50727
     Application url   :
    http://dicomweb/ReportServer/ReportBuilder/RptBuilder_3/MSReportBuilder.exe.manifest
          Server  : Microsoft-HTTPAPI/2.0
          X-AspNet-Version: 2.0.50727
    IDENTITIES
     Deployment Identity  : ReportBuilder_3_0_0_0.application, Version=10.50.6000.34, Culture=neutral, PublicKeyToken=c3bce3770c238a49, processorArchitecture=x86
     Application Identity  : MSReportBuilder.exe, Version=10.50.6000.34, Culture=neutral, PublicKeyToken=c3bce3770c238a49, processorArchitecture=x86, type=win32
    APPLICATION SUMMARY
     * Online only application.
     * Trust url parameter is set.
    ERROR SUMMARY
     Below is a summary of the errors, details of these errors are listed later in the log.
     * Activation of
    http://dicomweb/ReportServer/ReportBuilder/ReportBuilder_3_0_0_0.application resulted in exception. Following failure messages were detected:
      + File, Microsoft.ReportingServices.ComponentLibrary.Controls.dll, has a different computed hash than specified in manifest.
    COMPONENT STORE TRANSACTION FAILURE SUMMARY
     No transaction error was detected.
    WARNINGS
     There were no warnings during this operation.
    OPERATION PROGRESS STATUS
     * [10/15/2014 9:35:56 AM] : Activation of
    http://dicomweb/ReportServer/ReportBuilder/ReportBuilder_3_0_0_0.application has started.
     * [10/15/2014 9:36:29 AM] : Processing of deployment manifest has successfully completed.
     * [10/15/2014 9:36:29 AM] : Installation of the application has started.
     * [10/15/2014 9:36:31 AM] : Processing of application manifest has successfully completed.
     * [10/15/2014 9:36:35 AM] : Found compatible runtime version 2.0.50727.
     * [10/15/2014 9:36:35 AM] : Detecting dependent assembly Sentinel.v3.5Client, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=msil using Sentinel.v3.5Client, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a,
    processorArchitecture=msil.
     * [10/15/2014 9:36:35 AM] : Detecting dependent assembly System.Data.Entity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=msil using System.Data.Entity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089,
    processorArchitecture=msil.
     * [10/15/2014 9:36:35 AM] : Request of trust and detection of platform is complete.
    ERROR DETAILS
     Following errors were detected during this operation.
     * [10/15/2014 9:36:43 AM] System.Deployment.Application.InvalidDeploymentException (HashValidation)
      - File, Microsoft.ReportingServices.ComponentLibrary.Controls.dll, has a different computed hash than specified in manifest.
      - Source: System.Deployment
      - Stack trace:
       at System.Deployment.Application.ComponentVerifier.VerifyFileHash(String filePath, Hash hash)
       at System.Deployment.Application.ComponentVerifier.VerifyFileHash(String filePath, HashCollection hashCollection)
       at System.Deployment.Application.ComponentVerifier.VerifyComponents()
       at System.Deployment.Application.DownloadManager.DownloadDependencies(SubscriptionState subState, AssemblyManifest deployManifest, AssemblyManifest appManifest, Uri sourceUriBase, String targetDirectory, String group, IDownloadNotification
    notification, DownloadOptions options)
       at System.Deployment.Application.ApplicationActivator.DownloadApplication(SubscriptionState subState, ActivationDescription actDesc, Int64 transactionId, TempDirectory& downloadTemp)
       at System.Deployment.Application.ApplicationActivator.InstallApplication(SubscriptionState& subState, ActivationDescription actDesc)
       at System.Deployment.Application.ApplicationActivator.PerformDeploymentActivation(Uri activationUri, Boolean isShortcut, String textualSubId, String deploymentProviderUrlFromExtension, BrowserSettings browserSettings, String& errorPageUrl)
       at System.Deployment.Application.ApplicationActivator.ActivateDeploymentWorker(Object state)
    COMPONENT STORE TRANSACTION DETAILS
     No transaction information is available.

    Hi DMcGarveyt,
    This is an known issue in SSRS 2008 R2 SP3. For this issue, Microsoft has published an article addressing this issue. It is not planning to release a fix for this defect. But there's workarounds for this issue. Please refer to the link below:
    Report Builder of SQL Server 2008 R2 Service Pack 3 does not launch.
    If you have any question, please feel free to ask.
    Best Regards,
    Simon Hou

  • How to transfer the tables from one file group to another file group in SQL 2008.?

    Hello all,
    I have few issues regarding the transfer of the tables from one file group to another file group  in SQL 2008 and also How can we  backup
    and restore the particular database based on file group level.
    Let’s say I have a tables stored within the different FG. such as
    Tables                                                    
      File group
    Dimension tables                                              
                                                                     Primary
    Fact tables                                               
                                                                              FG1
               FG2…
    zzz_tables                                               
                                                                              DEFAULT_FG    
    dim.table1                                                                                                                          DEFAULT_FG
    dim.table2                                                                                                                          DEFAULT_FG
    Here all I want to transfer the dim.table1 ,dim.table2  from  DEFAULT_FG to the Primary File
    group .So is there simple methods for transfer the dim.table1,2  from one FG to another .I have tried somewhat but I couldn’t get the exact way .So if someone have better idea please share your knowledge that would be really appreciated.
    Secondly after moving those dim.table1 ,dim.table2 from DEFAULT_FG to Primary ,All I want to backup and restore the database only containing  the Primary and FG1,FG2… not
    a DEFAULT_FG.Is it possible or not.?
    Hope to hear from the one who knows better approach for this kind of task .Your simple help will be much appreciated.
    Regards,
    Anil Maharjan

    Well after all my full day research on this topic had paid off, I finally got the solution and am so happy to research on these things. It makes
    us feel really happy after all our research and hard work doesn't goes as waste.
    Finally I got what I am looking for and want to make sure that I am able to transfer the tables from DEFAULT_FG to another FG without tables
    having clustered index on that tables .
    With the help of the link below I finally got my solution where Roberto’s coded store procedure simply works for this.
    Really thanks to him for his great post and thanks to all for your response and your valuable time.
    http://gallery.technet.microsoft.com/scriptcenter/c1da9334-2885-468c-a374-775da60f256f
    Regards,
    Anil Maharjan

Maybe you are looking for

  • How to create a new aspx page in Pages library using Elements.xml without including any aspx page layout in my feature?

    Is it possible to have the elements.xml file create a page in the Pages (or SitePages) library without actually including any sort of page layout or aspx artifact in the feature? I see no reason to add a mywebpartlayout.aspx to my feature just so I c

  • Problem with enabling thai language in forms

    Hi all, I am using forms6i, oracle10g db(client/server environment), NLS_LANG is:thai_thailand.th8tisascii, our font standard is:ARIAL when i give an i/p via forms the typed value is showing as junk characters.if i change the font for the particular

  • Is 3.0.9 available?

    Is oracle portal 3.0.9 for NT available for download? if so were is it? thank's in advance Mauro null

  • JFrame doesn't really redraw...

    I made a Projekt for Seek and Exchange, using a JFrame as MainFrame. If a User klicks on 'Do it' the Program seeks in files, and shows the results in a Panel, I init. in another Panel of the MainFrame (BorderLayout:South), and... nothing, theres no e

  • No sim error on ios 5.1

    I updadted my iPhone 4S to ios 5.1. I now get a no SIM error. I have tried the usual ejectin sim, powering off etc