Search Results

Search found 37012 results on 1481 pages for 'sql query'.

Page 86/1481 | < Previous Page | 82 83 84 85 86 87 88 89 90 91 92 93  | Next Page >

  • SQL Server 2005 SP3 Express Backups Incredibly Slow

    - by Adam Robinson
    I'm attempting to troubleshoot an issue with one of our customers who's using SQL Server 2005 SP3 Express to house their application data. The automatic backups that we perform when upgrading our application are timing out after 30 minutes, and I've been sitting and watching the backup take place in SSMS for about 20 minutes now and it's only gotten to 30%. The database is only slightly over 1GB, so I'm baffled as to what could be causing this sort of horrible performance. The machine is a 1.87GHz Xeon with 3GB of RAM running Windows Server 2003 R2. While that's hardly a powerful box, this seems ridiculous. Does anyone have any idea why these backups could be taking so long and, more importantly, how I can do something about it?

    Read the article

  • Speeding up ROW_NUMBER in SQL Server

    - by BlueRaja
    We have a number of machines which record data into a database at sporadic intervals. For each record, I'd like to obtain the time period between this recording and the previous recording. I can do this using ROW_NUMBER as follows: WITH TempTable AS ( SELECT *, ROW_NUMBER() OVER (PARTITION BY Machine_ID ORDER BY Date_Time) AS Ordering FROM dbo.DataTable ) SELECT [Current].*, Previous.Date_Time AS PreviousDateTime FROM TempTable AS [Current] INNER JOIN TempTable AS Previous ON [Current].Machine_ID = Previous.Machine_ID AND Previous.Ordering = [Current].Ordering + 1 The problem is, it goes really slow (several minutes on a table with about 10k entries) - I tried creating separate indicies on Machine_ID and Date_Time, and a single joined-index, but nothing helps. Is there anyway to rewrite this query to go faster?

    Read the article

  • Setting up a SQL server outside the domain

    - by user12391
    Hi, im very new to this. I've set up an account "SQLBOX" thats on the a network, but not connected to the domain. I have installed an instance of SQL Server 2008 and am trying to connect to it from another machine on the network but am getting "Cannot connect to "SQLBOX"". From the "SQLBOX" i can connect to sqlservers on the domain, but not vice-versa. Any help would be greatly appreciated. Sorry if the description isn't great. EDIT I can ping the box from a machine on the domain

    Read the article

  • SQL Server Migration Assistant for Oracle problem

    - by Paul
    I've recently installed SSMA on my computer and after connecting to both the Oracle instance (which holds the database to be converted) and the SQL Server. I've mapped the needed schemas from oracle to mssql. The problem is that when i click on the report button for the assessment report there's an error popping up: Assesment Error : Nothing to Process The output window states: Starting conversion... Analyzing metadata... Conversion finished with 0 errors, 0 warnings, and 0 informational messages. There is nothing to process. Has anyone got experience with SSMA. I can't figure out what I am doing wrong. Thank you.

    Read the article

  • SQL 2008 managing 2 Instances on single Physical server

    - by Rajeev
    Hi, I need some calrification about managing SQL server 2008. The scenario is as follows: I have One Windows Physical server at Primary site, I want to have Two different applications database on it, so shall I create two Instances on same server or shall have diffenrent server for another database. First Database is for management purpose while second would be used for Reporting purpose. There is a second database at the secondary site, which will be in Passive mode and I intend to connect them through MSCS. Now, can I have both Instances on Single server and both will work fine? The management database will be used more. Please reply soon. Can both Instances have dedicated reources allocated to them?

    Read the article

  • replace set of integers with respective string values

    - by Tripz
    I have a query which return the output like -- 5,4,6 Where 1 = apple, 2 = mango, 3 = banana, 4 = plum, 5 = cherry, 6 = kiwi etc. I would like to update my output as cherry,plum,kiwi instead of 5,4,6 How can I achieve that in the same select statment. I am okay to hard code the values. Please confirm May be I did explain clearly Here is the sample SELECT fruits FROM t_fruitid where id = 7 is returning me '5,6,4' as a single row Now I want to update this single row output as 'cherry,plum,kiwi' How do I do this Thanku

    Read the article

  • Can Ping but Cannot Telnet directly to SQL Server 2012 Cluster Nodes

    - by tresstylez
    We have a monitoring tool (Solarwinds Orion) that needs to connect to a 2-node failover SQL Server Cluster. For reasons outside of our control -- we cannot monitor the CLUSTER IP directly at this time, so we have fallen back to monitoring each cluster node IP directly. This is not working. Upon troubleshooting, we tried to test that the cluster node was listening on the proper (fixed) port by using telnet to the cluster node IP/port -- and the telnet failed. However, telnet'ing to the Cluster IP/Port was SUCCESSFUL! Each node has its own IP. Each node is listening on the identical FIXED port. Each node has Dynamic Ports disabled. Each node can be PINGED successfully from the monitoring tool. Windows Firewall is DISABLED. How can I troubleshoot why I cannot telnet to the listening port on the cluster nodes?

    Read the article

  • Can only connect to sql server express 2012 via named pipes

    - by YetAnotherDeveloper
    I have sql server express 2012 installed on windows 2008, locally everything works just fine i can connect via tcpip and named pipes. Remotely i can connect with ssms only using named pipes. I have tried disabling the firewall on both sides to eliminate blocking traffic. i have toggled the tcpip setting on and off (i read somewhere that they got it working just but flipping them off and back on). I have double/triple checked all the settings that i'm aware of and everything seems to be correct. Tcp is enabled Tcp port is set to 1433, udp port is set to 1434 Server has static ip Start up log says: Server is listening on [ 'any' 1433]. Firewall rules are in place Any suggestions on things that i can look into? i have really just run out of ideas.

    Read the article

  • SQL-Server 2008 : Table Insert and Range Check ?

    - by LB .
    I'm using the Table Value constructor to insert a bunch of rows at a time. However if i'm using sql replication, I run into a range check constraint on the publisher on my id column managed automatically. The reason is the fact that the id range doesn't seem to be increased during an insert of several values, meaning that the max id is reached before the actual range expansion could occur (or the id threshold). It looks like this problem for which the solution is either running the merge agent or run the sp_adjustpublisheridentityrange stored procedure. I'm litteraly doing something like : INSERT INTO dbo.MyProducts (Name, ListPrice) VALUES ('Helmet', 25.50), ('Wheel', 30.00), ((SELECT Name FROM Production.Product WHERE ProductID = 720), (SELECT ListPrice FROM Production.Product WHERE ProductID = 720)); GO What are my options (if I don't want or can't adopt any of the proposed solution) ? Expand the range ? Decrease the threshold ? Can I programmatically modify my request to circumvent this problem ? thanks.

    Read the article

  • SQL Server database constantly restarting

    - by Michael Itzoe
    We have SQL Server 2008 Express installed on a Windows 2003 server. Looking at the event log, one of the databases appears to be restarting anywhere from every couple seconds to every 15 to 30 minutes. This server hosts about half a dozen databases; the problem is with only one. This database is also the onle one comprised of multiple schemas (not just dbo). There are thousands of events going back several months. There doesn't seem to be any affect on the website using the database, nor does any data appear to be corrupted or compromised. I'm not a DBA, so I don't even know where to look for causes to this. Any suggestions?

    Read the article

  • SQL Server - MVP 2010

    - by JustinL
    I was very happy to receive an email last week to confirm I would receive the MVP Award for SQL Server for 2010 - very exciting news ! I missed the first FedEx delivery, however this weekend they were able to successfully deliver the package from Microsoft and it began to feel very real as I opened the box to find the MVP glass-ware! Since leaving Microsoft, the past couple of years have been incredibly challenging, exciting and satisfying.  The MVP Award is really special, the SQL community has a fantastic, international base with many successful events, leaders and contributors providing an impressive network both online and in-person. I'm really excited about the year ahead - starting this week with SQL Bits in London, followed by PASS EMEA in Germany next week and at the London PASS user group meeting on Monday 26th April. Regards,   Justin Langford - Coeo Ltd

    Read the article

  • The final Cumulative Update for SQL Server 2008 SP3

    - by AaronBertrand
    Microsoft has released the final Cumulative Update (#17) for SQL Server 2008 Service Pack 3. Build # 10.00.5861 KB Article: KB #2958696 9 public fixes Relevant for builds 10.00.5500 -> 10.00.5860 NOT for SQL Server 2008 R2 (10.50.xxxx) Once more, this is the last cumulative update for SQL Server 2008. Both 2008 and 2008 R2 exit mainstream support in July of this year. That's two months away. If you want a final service pack for either or both of these major versions, and want your voice heard,...(read more)

    Read the article

  • The final Cumulative Update for SQL Server 2008 SP3

    - by AaronBertrand
    Microsoft has released the final Cumulative Update (#17) for SQL Server 2008 Service Pack 3. Build # 10.00.5861 KB Article: KB #2958696 9 public fixes Relevant for builds 10.00.5500 -> 10.00.5860 NOT for SQL Server 2008 R2 (10.50.xxxx) Once more, this is the last cumulative update for SQL Server 2008. Both 2008 and 2008 R2 exit mainstream support in July of this year. That's two months away. If you want a final service pack for either or both of these major versions, and want your voice heard,...(read more)

    Read the article

  • October 2013 Cumulative Update for SQL Server 2008 R2

    - by AaronBertrand
    Microsoft has released Cumulative Update #9 for SQL Server 2008 R2 Service Pack 2. KB Article: KB #2887606 17 fixes listed at time of publication Build number is 10.50.4295 Relevant for @@VERSION 10.50.4000 through 10.50.4294 My usual disclaimer: these updates are NOT for SQL Server 2008 (or SQL Server 2012). Only apply to systems where SELECT @@VERSION returns 10.50.xxxx, where xxxx is >= 2500. If xxxx < 2500, you need to start thinking about getting off the RTM branch. Note that no more cumulative...(read more)

    Read the article

  • Want to Learn SQL Server 2012?

    - by andyleonard
    Or SSIS 2012? SSRS 2012? SSAS 2012? There’s no substitute for getting your hands on the product, in my opinion. I can hear you thinking, “But Andy, I can’t afford to purchase a copy of SQL Server 2012.” Are you sure? What if I told you that you can get a full-feature version of SQL Server 2012 Enterprise Edition for $50? Well, you cannot… it’s actually less than $50! SQL Server 2012 Developer Edition is available at Amazon on the day of this writing for $41.24USD. That’s about the price of eight...(read more)

    Read the article

  • SQL Sentry Plan Explorer : Version 1.1!

    - by AaronBertrand
    Last week, Microsoft offered up an early Christmas present: SQL Server 2005 SP4 . This week, it's SQL Sentry 's turn to play Santa Claus: several new features and fixes have been packaged up into SQL Sentry Plan Explorer 1.1 (build 6.0.67.0). So, what's new? Several wish list items have been fulfilled (hey, it is Christmas, after all). You can see the full change list here ; but I'll talk briefly about a few of my favorites: Parallel distribution The Plan Tree tab for a parallel operator now shows...(read more)

    Read the article

  • A Year of Tuesdays: T-SQL Tuesday Meta-Roundup

    - by Adam Machanic
    Just over a year ago I kicked off T-SQL Tuesday , "a recurring, revolving blog party." The idea was simple: Each month a blog will host the party, and about a week before the second Tuesday of the month a theme will be posted. Any blogger that wishes to participate is invited to write a post on the chosen topic. The event is called "T-SQL Tuesday", but any post that is related to both SQL Server and the theme is fair game . So feel free to post about SSIS, SSRS, Java integration, or whatever other...(read more)

    Read the article

  • SQL Server 2012 Cumulative Update #1 is available!

    - by AaronBertrand
    While I joked earlier this month that SQL Server 2012 Service Pack 1 was released on the same day as General Availability (hey, it's Microsoft's fault since they decided to GA on April 1), this time it isn't a joke. Today Microsoft has released Cumulative Update #1 for SQL Server 2012 . About half of the fixes affect the database engine. Analysis Services and Data Quality Services make up the bulk of the remainder. If you're running SQL Server 2012 now, I suggest you apply the update. This would...(read more)

    Read the article

  • Stairway to T-SQL DML Level 4: The Mathematics of SQL: Part 1

    A relational database contains tables that relate to each other by key values. When querying data from these related tables you may choose to select data from a single table or many tables. If you select data from many tables, you normally join those tables together using specified join criteria. The concepts of selecting data from tables and joining tables together is all about managing and manipulating sets of data. In Level 4 of this Stairway we will explore the concepts of set theory and mathematical operators to join, merge, and return data from multiple SQL Server tables. Get Smart with SQL Backup Pro Powerful centralised management, encryption and more.SQL Backup Pro was the smartest kid at school Discover why.

    Read the article

  • Managing User & Role Security with Oracle SQL Developer

    - by thatjeffsmith
    With the advent of SQL Developer v3.0, users have had access to some powerful database administration features. Version 3.1 introduced more powerful features such as an interface to Data Pump and RMAN. Today I want to talk about some very simple but frequently ran tasks that SQL Developer can assist with, like: identifying privs granted to users managing role privs assigning new roles and privs to users & roles Before getting started, you’ll need a connection to the database with the proper privileges. The common ROLE used to accomplish this is the ‘DBA‘ role. Curious as to what the DBA role is actually comprised of? Let’s find out! Open the DBA Console First make sure you’re connected to the database you want to manage security on with a privileged administrator account. Then open the View menu and select ‘DBA.’ Accessing the DBA panel ‘Create’ a Connection Click on the green ‘+’ button in the DBA panel. It will ask you to choose a previously defined SQL Developer connection. Defining a DBA connection in Oracle SQL Developer Once connected you will see a tree list of DBA features you can start interacting with. Expand the ‘Security’ Tree Node As you click on an object in the DBA panel, the ‘viewer’ will open on the right-hand-side, just like you are accustomed to seeing when clicking on a table or stored procedure. Accessing the DBA role If I’m a newly hired Oracle DBA, the first thing I might want to do is become very familiar with the DBA role. People will be asking you to grant them this role or a subset of its privileges. Once you see what the role can do, you will become VERY protective of it. My favorite 3-letter 4-letter word is ‘ANY’ and the DBA role is littered with privileges like this: ANY TABLE privs granted to DBA role So if this doesn’t freak you out, then maybe you should re-consider your career path. Or in other words, don’t be granting this role to ANYONE you don’t completely trust to take care of your database. If I’m just assigned a new database to manage, the first thing I might want to look at is just WHO has been assigned the DBA role. SQL Developer makes this easy to ascertain, just click on the ‘User Grantees’ panel. Who has the keys to your car? Making Changes to Roles and Users If you mouse-right-click on a user in the Tree, you can do individual tasks like grant a sys priv or expire an account. But, you can also use the ‘Edit User’ dialog to do a lot of work in one pass. As you click through options in these dialogs, it will build the ‘ALTER USER’ script in the SQL panel, which can then be executed or copied to the worksheet or to your .SQL file to be ran at your discretion. A Few Clicks vs a Lot of Typing These dialogs won’t make you a DBA, but if you’re pressed for time and you’re already in SQL Developer, they can sure help you make up for lost time in just a few clicks!

    Read the article

  • Write TSQL, win a Kindle.

    - by Fatherjack
    So recently Red Gate launched sqlmonitormetrics.red-gate.com and showed the world how to embed your own scripts harmoniously in a third party tool to get the details that you want about your SQL Server performance. The site has a way to submit your own metrics and take a copy of the ones that other people have submitted to build a library of code to keep track of key metrics of your servers performance. There have been several submissions already but they have now launched a competition to provide an incentive for you to get creative and show us what you can do with a bit of TSQL and the SQL Monitor framework*. What’s it worth? Well, if you are one of the 3 winners then you get to choose either a Kindle Fire or $199. How do you win? Simply write the T-SQL for a SQL Monitor custom metric and the relevant description and introduction for it and submit it via  sqlmonitormetrics.red-gate.com before 14th Sept 2012 and then sit back and wait while the judges review your code and your aims in writing the metric. Who are the judges and how will they judge the metrics? There are two judges for this competition, Steve Jones (Microsoft SQL Server MVP, co-founder of SQLServerCentral.com, author, blogger etc) and Jonathan Allen (um, yeah, Steve has done all the good stuff, I’m here by good fortune). We will be looking to rate the metrics on each of 3 criteria: how the metric can help with performance tuning SQL Server. how having the metric running enables DBA’s to meet best practice. how interesting /original the idea for the metric is. Our combined decision will be final etc etc **  What happens to my metric? Any metrics submitted to the competition will be automatically entered into the site library and become available for sharing once the competition is over. You’ll get full credit for metrics you submit regardless of the competition results. You can enter as many metrics as you like. How long does it take? Honestly? Once you have the T-SQL sorted then so long as you can type your name and your email address you are done : http://sqlmonitormetrics.red-gate.com/share-a-metric/ What can I monitor? If you really really want a Kindle or $199 (and let’s face it, who doesn’t? ) and are momentarily stuck for inspiration, take a look at these example custom metrics that have been written by Stuart Ainsworth, Fabiano Amorim, TJay Belt, Louis Davidson, Grant Fritchey, Brad McGehee and me  to start the library off. There are some great pieces of TSQL in those metrics gathering important stats about how SQL Server is performing.   * – framework may not be the best word here but I was under pressure and couldnt think of a better one. If you prefer try ‘engine’, or ‘application’? I don’t know, pick something that makes sense to you. ** – for the full (legal) version of the rules check the details on sqlmonitormetrics.red-gate.com or send us an email if you want any point clarified. Disclaimer – Jonathan is a Friend of Red Gate and as such, whenever they are discussed, will have a generally positive disposition towards Red Gate tools. Other tools are often available and you should always try others before you come back and buy the Red Gate ones. All code in this blog is provided “as is” and no guarantee, warranty or accuracy is applicable or inferred, run the code on a test server and be sure to understand it before you run it on a server that means a lot to you or your manager.

    Read the article

  • SQL query mixing aggregated results and single values

    - by Paul Flowerdew
    I have a table with transactions. Each transaction has a transaction ID, and accounting period (AP), and a posting value (PV), as well as other fields. Some of the IDs are duplicated, usually because the transaction was done in error. To give an example, part of the table might look like: ID PV AP 123 100 2 123 -100 5 In this case the transaction was added in AP2 then removed in AP5. Another example would be: ID PV AP 456 100 2 456 -100 5 456 100 8 In the first example, the problem is that if I am analyzing what was spent in AP2, there is a transaction in there which actually shouldn't be taken into account because it was taken out again in AP5. In the second example, the second two transactions shouldn't be taken into account because they cancel each other out. I want to label as many transactions as possible which shouldn't be taken into account as erroneous. To identify these transactions, I want to find the ones with duplicate IDs whose PVs sum to zero (like ID 123 above) or transactions where the PV of the earliest one is equal to sum(PV), as in the second example. This second condition is what is causing me grief. So far I have SELECT * FROM table WHERE table.ID IN (SELECT table.ID FROM table GROUP BY table.ID HAVING COUNT(*) > 1 AND (SUM(table.PV) = 0 OR SUM(table.PV) = <PV of first transaction in each group>)) ORDER BY table.ID; The bit in chevrons is what I'm trying to do and I'm stuck. Can I do it like this or is there some other method I can use in SQL to do this? Edit 1: Btw I forgot to say that I'm using SQL Compact 3.5, in case it matters. Edit 2: I think the code snippet above is a bit misleading. I still want to mark out transactions with duplicate IDs where sum(PV) = 0, as in the first example. But where the PV of the earliest transaction = sum(PV), as in the second example, what I actually want is to keep the earliest transaction and mark out all the others with the same ID. Sorry if that caused confusion. Edit 3: I've been playing with Clodoaldo's solution and have made some progress, but still can't get quite what I want. I'm trying to get the transactions I know for certain to be erroneous. Suppose the following transactions are also in the table: ID PV AP 789 100 2 789 200 5 789 -100 8 In this example sum(PV) < 0 and the earliest PV < sum(PV) so I don't want to mark any of these out. If I modify Clodoaldo's query as follows: select t.* from t left join ( select id, min(ap) as ap, sum(pv) as sum_pv from t group by id having sum(pv) <> 0 ) s on t.id = s.id and t.ap = s.ap and t.pv = s.sum_pv where s.id is null This gives the result ID PV AP 123 100 2 123 -100 5 456 -100 5 456 100 8 789 100 3 789 200 5 789 -100 8 Whilst the first 4 transactions are ok (they would be marked out), the 789 transactions are also there, and I don't want them. But I can't figure out how to modify the query so that they're not included. Any ideas?

    Read the article

  • SQL - date variable isn't being parsed correctly?

    - by Bill Sambrone
    I am pulling a list of invoices filtered by a starting and ending date, and further filtered by type of invoice from a SQL table. When I specify a range of 2013-07-01 through 2013-09-30 I am receiving 2 invoices per company when I expect 3. When I use the built in select top 1000 query in SSMS and add my date filters, all the expected invoices appear. Here is my fancy query that I'm using that utilizing variables that are fed in: DECLARE @ReportStart datetime DECLARE @ReportStop datetime SET @ReportStart = '2013-07-01' SET @ReportStop = '2013-09-30' SELECT Entity_Company.CompanyName, Reporting_AgreementTypes.Description, Reporting_Invoices.InvoiceAmount, ISNULL(Reporting_ProductCost.ProductCost,0), (Reporting_Invoices.InvoiceAmount - ISNULL(Reporting_ProductCost.ProductCost,0)), (Reporting_AgreementTypes.Description + Entity_Company.CompanyName), Reporting_Invoices.InvoiceDate FROM Reporting_Invoices JOIN Entity_Company ON Entity_Company.ClientID = Reporting_Invoices.ClientID LEFT JOIN Reporting_ProductCost ON Reporting_ProductCost.InvoiceNumber =Reporting_Invoices.InvoiceNumber JOIN Reporting_AgreementTypes ON Reporting_AgreementTypes.AgreementTypeID = Reporting_Invoices.AgreementTypeID WHERE Reporting_Invoices.AgreementTypeID = (SELECT AgreementTypeID FROM Reporting_AgreementTypes WHERE Description = 'Resold Services') AND Reporting_Invoices.InvoiceDate >= @ReportStart AND Reporting_Invoices.InvoiceDate <= @ReportStop ORDER BY CompanyName,InvoiceDate The above only returns 2 invoices per company. When I run a much more basic query through SSMS I get 3 as expected, which looks like: SELECT TOP 1000 [InvoiceID] ,[AgreementID] ,[AgreementTypeID] ,[InvoiceDate] ,[Comment] ,[InvoiceAmount] ,[InvoiceNumber] ,[TicketID] ,Entity_Company.CompanyName FROM Reporting_Invoices JOIN Entity_Company ON Entity_Company.ClientID = Reporting_Invoices.ClientID WHERE Entity_Company.ClientID = '9' AND AgreementTypeID = (SELECT AgreementTypeID FROM Reporting_AgreementTypes WHERE Description = 'Resold Services') AND Reporting_Invoices.InvoiceDate >= '2013-07-01' AND Reporting_Invoices.InvoiceDate <= '2013-09-30' ORDER BY InvoiceDate DESC I've tried stripping down the 1st query to include only a client ID on the original invoice table, the invoice date, and nothing else. Still only get 2 invoices instead of the expected 3. I've also tried manually entering the dates instead of the @ variables, same result. I confirmed that InvoiceDate is defined as a datetime in the table. I've tried making all JOIN's a FULL JOIN to see if anything is hiding, but no change. Here is how I stripped down the original query to keep all other tables out of the mix and yet I'm still getting only 2 invoices per client ID instead of 3 (I manually entered the ID for the type filter): --DECLARE @ReportStart datetime --DECLARE @ReportStop datetime --SET @ReportStart = '2013-07-01' --SET @ReportStop = '2013-09-30' SELECT --Entity_Company.CompanyName, --Reporting_AgreementTypes.Description, Reporting_Invoices.ClientID, Reporting_Invoices.InvoiceAmount, --ISNULL(Reporting_ProductCost.ProductCost,0), --(Reporting_Invoices.InvoiceAmount - ISNULL(Reporting_ProductCost.ProductCost,0)), --(Reporting_AgreementTypes.Description + Entity_Company.CompanyName), Reporting_Invoices.InvoiceDate FROM Reporting_Invoices --JOIN Entity_Company ON Entity_Company.ClientID = Reporting_Invoices.ClientID --LEFT JOIN Reporting_ProductCost ON Reporting_ProductCost.InvoiceNumber = Reporting_Invoices.InvoiceNumber --JOIN Reporting_AgreementTypes ON Reporting_AgreementTypes.AgreementTypeID = Reporting_Invoices.AgreementTypeID WHERE Reporting_Invoices.AgreementTypeID = '22'-- (SELECT AgreementTypeID FROM Reporting_AgreementTypes WHERE Description = 'Resold Services') AND Reporting_Invoices.InvoiceDate >= '2013-07-01' AND Reporting_Invoices.InvoiceDate <= '2013-09-30' ORDER BY ClientID,InvoiceDate This strikes me as really weird as it is pretty much the same query as the SSMS generated one that returns correct results. What am I overlooking? UPDATE I've further refined my "test query" that is returning only 2 invoices per company to help troubleshoot this. Below is the query and a relevant subset of data for 1 company from the appropriate tables: SELECT Reporting_Invoices.ClientID, Reporting_AgreementTypes.Description, Reporting_Invoices.InvoiceAmount, Reporting_Invoices.InvoiceDate FROM Reporting_Invoices JOIN Reporting_AgreementTypes ON Reporting_AgreementTypes.AgreementTypeID = Reporting_Invoices.AgreementTypeID WHERE Reporting_Invoices.AgreementTypeID = (SELECT AgreementTypeID FROM Reporting_AgreementTypes WHERE Description = 'Resold Services') AND Reporting_Invoices.InvoiceDate >= '2013-07-01T00:00:00' AND Reporting_Invoices.InvoiceDate <= '2013-09-30T00:00:00' ORDER BY Reporting_Invoices.ClientID,InvoiceDate The above only returns 2 invoices. Here is the relevant table data: Relevant data from Reporting_AgreementTypes AgreementTypeID Description 22 Resold Services Relevant data from Reporting_Invoices InvoiceID ClientID AgreementID AgreementTypeID InvoiceDate 16111 9 757 22 2013-09-30 00:00:00.000 15790 9 757 22 2013-08-30 00:00:00.000 15517 9 757 22 2013-07-31 00:00:00.000 Actual results from my new modified query ClientID Description InvoiceAmount InvoiceDate 9 Resold Services 3513.79 7/31/13 00:00:00 9 Resold Services 3570.49 8/30/13 00:00:00

    Read the article

  • Coping with infrastructure upgrades

    - by Fatherjack
    A common topic for questions on SQL Server forums is how to plan and implement upgrades to SQL Server. Moving from old to new hardware or moving from one version of SQL Server to another. There are other circumstances where upgrades of other systems affect SQL Server DBAs. For example, where I work at the moment there is an Microsoft Exchange (email) server upgrade in progress. It it being handled by a different team so I’m not wholly sure on the details but we are in a situation where there are currently 2 Exchange email servers – the old one and the new one. Users mail boxes are being transferred in a planned process but as we approach the old server being turned off we have to also make sure that our SQL Servers get updated to use the new SMTP server for all of the SQL Agent notifications, SSIS packages etc. My servers have a number of profiles so that various jobs can send emails on behalf of various departments and different systems. This means there are lots of places that the old server name needs to be replaced by the new one. Anyone who has set up DBMail and enjoyed the click-tastic odyssey of screens to create Profiles and Accounts and so on and so forth ought to seek some professional help in my opinion. It’s a nightmare of back and forth settings changes and it stinks. I wasn’t looking forward to heading into this mess of a UI and changing the old Exchange server name for the new one on all my SQL Instances for all of the accounts I have set up. So I did what any Englishmen with a shed would do, I decided to take it apart and see if I can fix it another way. I took a guess that we are going to be working in MSDB and Books OnLine was remarkably helpful and amongst a lot of information told me about a couple of procedures that can be used to interrogate DBMail settings. USE [msdb] -- It's where all the good stuff is kept GO EXEC dbo.sysmail_help_profile_sp; EXEC dbo.sysmail_help_account_sp; Both of these procedures take optional parameters with the same name – ID and Name. If you provide an ID or a name then the results you get back are for that specific Profile or Account. Otherwise you get details of all Profiles and Accounts on the server you are connected to. As you can see (click for a bigger image), the Account has the SMTP server information in the servername column. We want to change that value to NewSMTP.Contoso.com. Now it appears that the procedure we are looking at gets it’s data from the sysmail_account and sysmail_server tables, you can get the results the stored procedure provides if you run the code below. SELECT [account_id] , [name] , [description] , [email_address] , [display_name] , [replyto_address] , [last_mod_datetime] , [last_mod_user] FROM dbo.sysmail_account AS sa; SELECT [account_id] , [servertype] , [servername] , [port] , [username] , [credential_id] , [use_default_credentials] , [enable_ssl] , [flags] , [last_mod_datetime] , [last_mod_user] , [timeout] FROM dbo.sysmail_server AS sms Now, we have no real idea how these tables are linked and whether making an update direct to one or other of them is going to do what we want or whether it will entirely cripple our ability to send email from SQL Server so we wont touch those tables with any UPDATE TSQL. So, back to Books OnLine then and we find sysmail_update_account_sp. It’s exactly what we need. The examples in BOL take the form (as below) of having every parameter explicitly defined. Not wanting to totally obliterate the existing values by not passing values in all of the parameters I set to writing some code to gather the existing data from the tables and re-write the SMTP server name and then execute the resulting TSQL. IF OBJECT_ID('tempdb..#sysmailprofiles') IS NOT NULL DROP TABLE #sysmailprofiles GO CREATE TABLE #sysmailprofiles ( account_id INT , [name] VARCHAR(50) , [description] VARCHAR(500) , email_address VARCHAR(500) , display_name VARCHAR(500) , replyto_address VARCHAR(500) , servertype VARCHAR(10) , servername VARCHAR(100) , port INT , username VARCHAR(100) , use_default_credentials VARCHAR(1) , ENABLE_ssl VARCHAR(1) ) INSERT [#sysmailprofiles] ( [account_id] , [name] , [description] , [email_address] , [display_name] , [replyto_address] , [servertype] , [servername] , [port] , [username] , [use_default_credentials] , [ENABLE_ssl] ) EXEC [dbo].[sysmail_help_account_sp] DECLARE @TSQL NVARCHAR(1000) SELECT TOP 1 @TSQL = 'EXEC [dbo].[sysmail_update_account_sp] @account_id = ' + CAST([s].[account_id] AS VARCHAR(20)) + ', @account_name = ''' + [s].[name] + '''' + ', @email_address = N''' + [s].[email_address] + '''' + ', @display_name = N''' + [s].[display_name] + '''' + ', @replyto_address = N''' + s.replyto_address + '''' + ', @description = N''' + [s].[description] + '''' + ', @mailserver_name = ''NEWSMTP.contoso.com''' + +', @mailserver_type = ' + [s].[servertype] + ', @port = ' + CAST([s].[port] AS VARCHAR(20)) + ', @username = ' + COALESCE([s].[username], '''''') + ', @use_default_credentials =' + CAST(s.[use_default_credentials] AS VARCHAR(1)) + ', @enable_ssl =' + [s].[ENABLE_ssl] FROM [#sysmailprofiles] AS s WHERE [s].[servername] = 'SMTP.Contoso.com' SELECT @tsql EXEC [sys].[sp_executesql] @tsql This worked well for me and testing the email function EXEC dbo.sp_send_dbmail afterwards showed that the settings were indeed using our new Exchange server. It was only later in writing this blog that I tried running the sysmail_update_account_sp procedure with only the SMTP server name parameter value specified. Despite what Books OnLine might intimate, you can do this and only the values for parameters specified get changed. If a parameter is not specified in the execution of the procedure then the values remain unchanged. This renders most of the above script unnecessary as I could have simply specified the account_id that I want to amend and the new value for the parameter I want to update. EXEC sysmail_update_account_sp @account_id = 1, @mailserver_name = 'NEWSMTP.Contoso.com' This wasn’t going to be the main reason for this post, it was meant to describe how to capture values from a stored procedure and use them in dynamic TSQL but instead we are here and (re)learning the fact that Books Online is a little flawed in places. It is a fantastic resource for anyone working with SQL Server but the reader must adopt an enquiring frame of mind and use a little curiosity to try simple variations on examples to fully understand the code you are working with. I think the author(s) of this part of Books OnLine missed an opportunity to include a third example that had fewer than all parameters specified to give a lead to this method existing.

    Read the article

< Previous Page | 82 83 84 85 86 87 88 89 90 91 92 93  | Next Page >