Search Results

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

Page 50/1481 | < Previous Page | 46 47 48 49 50 51 52 53 54 55 56 57  | Next Page >

  • SQL Query Theory Question...

    - by Keng
    I have a large historical transaction table (15-20 million rows MANY columns) and a table with one row one column. The table with one row contains a date (last processing date) which will be used to pull the data in the trasaction table ('process_date'). Question: Should I inner join the 'process_date' table to the transaction table or the transaction table to the 'process_date' table?

    Read the article

  • Mind the gap, the latest version number for SQL Server 2008 R2 is....

    - by ssqa.net
    Since the news about SQL Server 2008 R2 RTM is publicised I have downloaded and installed the Evaluation edition and R2 Express edition. You can also download SQL Server 2008 R2 RTM - Management Studio Express (with pre-registration) The Microsoft® SQL Server® 2008 R2 RTM - Express is a powerful and reliable data management system that delivers a rich set of features, data protection, and performance for embedded applications, lightweight Web applications, and local data stores. Designed for easy...(read more)

    Read the article

  • How do I make complex SQL queries easier to write?

    - by DragonLord
    I'm finding it very difficult to write complex SQL queries involving joins across many (at least 3-4) tables and involving several nested conditions. The queries I'm being asked to write are easily described by a few sentences, but can require a deceptive amount of code to complete. I'm finding myself often using temporary views to write these queries, which seem like a bit of a crutch. What tips can you provide that I can use to make these complex queries easier? More specifically, how do I break these queries down into the steps I need to use to actually write the SQL code? Note that I'm the SQL I'm being asked to write is part of homework assignments for a database course, so I don't want software that will do the work for me. I want to actually understand the code I'm writing. More technical details: The database is hosted on a PostgreSQL server running on the local machine. The database is very small: there are no more than seven tables and the largest table has less than about 50 rows. The SQL queries are being passed unchanged to the server, via LibreOffice Base.

    Read the article

  • We are having a Social on the 15th April - Why not join us for some SQL fun

    - by NeilHambly
    TechDays are coming week, with the "SQL Server 2008 R2" Launch conference being held on the Thursday (15 th April) and followed by the much anticipated SQLBits VI the following day (16 th April) So we thought this an ideal opportunity to hold a SQL Social evening for those fortunate enough to be able to attend those conferences or just wanted to join us for the evening It is being held @ "The Bull" Pub @ Westfield centre (only a short walk from the venue of t the “SQL Server 2008...(read more)

    Read the article

  • Which Edition of SQL Server 2008 R2 should you use?

    - by BuckWoody
    SQL Server 2008 R2 has just released to manufacturing (RTM’d) as I write this. With each new release, we make changes to the “Editions” we offer. A SQL Server “version” deals with the major changes in the product – and “edition” is a set of features and capabilities within that version (you’re welcome). So… definitely run over to http://msdn.microsoft.com/en-us/library/cc645993(v=SQL.105).aspx and check out the changes. For instance, did you know that SQL Server Express now supports 10GB databases? Well, then get over there and read what each edition does. Share this post: email it! | bookmark it! | digg it! | reddit! | kick it! | live it!

    Read the article

  • How to use CASE in SQL , Syntax Error being shown

    - by Shantanu Gupta
    I am trying to retrieve some records from table based on my query but it shows me an error Msg 102, Level 15, State 1, Line 2 Incorrect syntax near ' select vd.LedgerId,(CreditAmt-DebitAmt) AS NET, CASE NET WHEN NET > 0 THEN 'Debit' WHEN NET < 0 THEN 'Credit' ELSE 'Nil'End from dbo.vdebit vd INNER JOIN dbo.vCredit vc ON vd.LedgerId=vc.LedgerId

    Read the article

  • Is there an equivalent of "OPTION(RECOMPILE)" or "WITH RECOMPILE" for an entire connection?

    - by kamens
    I'm curious. Is there any way to prevent SQL query execution plans from being cached for an entire connection's duration? Can I run a command that basically says, "use OPTION(RECOMPILE) for all subsequent commands until I tell you to stop doing so?" I'm acutely aware of all the performance trade-offs here, and I know this is not a step to be taken lightly. However, I'm in a unique situation where this behavior may be advantageous.

    Read the article

  • SQL, Auxiliary table of numbers

    - by vzczc
    For certain types of sql queries, an auxiliary table of numbers can be very useful. It may be created as a table with as many rows as you need for a particular task or as a user defined function that returns the number of rows required in each query. What is the optimal way to create such a function?

    Read the article

  • Exceptions handling in SQL?

    - by Vineet
    Is there any way to handle exceptions in sql(ORACLE 9i)? Since I was trying to divide values of a column that contains both numbers and literals ,I need to fetch out only numbers from it ,as if it divisible by any number then its number else if contains literals it would not get divided it will generate error. how to handle those errors? Please suggest!!

    Read the article

  • Fix: Connections to SQL Server 2005 on Windows Vista suddenly stop working

    - by NTulip
    On my Vista machine at work, applications and the SQL Server Management Console work fine connecting to SQL Server 2005. Sometimes they are ok for weeks at a time, sometime for hours and then they stop connecting. I've tried everything to get it to work including the installation of SPII and running the user provisioning tool without any luck. The only way to fix it was to restart. The Error: Connections are refused with the standard error message: Cannot connect to SERVER_NAME\INSTANCE_NAME ------------------------------ ADDITIONAL INFORMATION: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified) (Microsoft SQL Server, Error: -1) For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&EvtSrc=MSSQLServer&EvtID=-1&LinkId=20476 The Fix: Stop and restart the Sql Server Browser, Sql Server integration, SQL Server Active Directory Helper services. Works like a charm.

    Read the article

  • Advice needed: warm backup solution for SQL Server 2008 Express?

    - by Mikey Cee
    What are my options for achieving a warm backup server for a SQL Server Express instance running a single database? Sitting beside my production SQL Server 2008 Express box I have a second physical box currently doing nothing. I want to use this second box as a warm backup server by somehow replicating my production database in near real time (a little bit of data loss is acceptable). The database is very small and resources are utilized very lightly. In the case that the production server dies, I would manually reconfigure my application to point to the backup server instead. Although Express doesn't support log shipping natively, I am thinking that I could manually script a poor man's version of it, where I use batch files to take the logs and copy them across the network and apply them to the second server at 5 minute intervals. Does anyone have any advice on whether this is technically achievable, or if there is a better way to do what I am trying to do? Note that I want to avoid having to pay for the full version of SQL Server and configure mirroring as I think it is an overkill for this application. I understand that other DB platforms may present suitable options (eg. a MySQL Cluster), but for the purposes of this discussion, let's assume we have to stick to SQL Server.

    Read the article

  • sql query where parameters null not null

    - by Laziale
    I am trying to do a sql query and to build the where condition dynamically depending if the parameters are null or no. I have something like this: SELECT tblOrder.ProdOrder, tblOrder.Customer FROM tblOrder CASE WHEN @OrderId IS NOT NULL THEN WHERE tblOrder.OrderId = @OrderId ELSE END CASE WHEN @OrderCustomer IS NOT NULL THEN AND tblOrder.OrderCustomer = @OrderCustomer ELSE END END This doesn't work, but this is just a small prototype how to assemble the query, so if the orderid is not null include in the where clause, or if the ordercustomer is not null include in the where clause. But I see problem here, for example if the ordercustomer is not null but the orderid is null, there will be error because the where keyword is not included. Any advice how I can tackle this problem. Thanks in advance, Laziale

    Read the article

  • Execution plan issue requires reset on SQL Server 2005, how to determine cause?

    - by Tony Brandner
    We have a web application that delivers training to thousands of corporate students running on top of SQL Server 2005. Recently, we started seeing that a single specific query in the application went from 1 second to about 30 seconds in terms of execution time. The application started throwing timeouts in that area. Our first thought was that we may have incorrect indexes, so we reviewed the tables and indexes. However, similar queries elsewhere in the application also run quickly. Reviewing the indexes showed us that they were configured as expected. We were able to narrow it down to a single query, not a stored procedure. Running this query in SQL Studio also runs quickly. We tried running the application in a different server environment. So a different web server with the same query, parameters and database. The query still ran slow. The query is a fairly large one related to determining a student's current list of training. It includes joins and left joins on a dozen tables and subqueries. A few of the tables are fairly large (hundreds of thousands of rows) and some of the other tables are small lookup tables. The query uses a grouping clause and a few where conditions. A few of the tables are quite active and the contents change often but the volume of added rows doesn't seem extreme. These symptoms led us to consider the execution plan. First off, as soon as we reset the execution plan cache with the SQL command 'DBCC FREEPROCCACHE', the problem went away. Unfortunately, the problem started to reoccur within a few days. The problem has continued to plague us for awhile now. It's usually the same query, but we did appear to see the problem occur in another single query recently. It happens enough to be a nuisance. We're having a heck of a time trying to fix it since we can't reproduce it in any other environment other than production. I have downloaded the High Availability guide from Red Gate and I read up more on execution plans. I hope to run the profiler on the live server, but I'm a bit concerned about impact. I would like to ask - what is the best way to figure out what is triggering this problem? Has anyone else seen this same issue?

    Read the article

  • Error: An aggregate may not appear in the WHERE clause unless it is in a subquery contained in a HAV

    - by brz dot net
    I have to find the indentid from the status table based on below two conditions: 1. If there are more than one record having same indentid in status table and the same indentID has count1 in feasibilitystatus table then I don't want to display the record. 2. If there is only one record of indentid in status table and the same indentID has count0 in feasibilitystatus table then I don't want to display the record. Query: select distinct s.indentid from status s where s.status='true' and s.indentid not in( select case when count(s.indentid)>1 then (select indentid from feasibilitystatus group by indentid having count(indentid)>1) else (select indentid from feasibilitystatus group by indentid having count(indentid)>0) end as indentid from status) Error: An aggregate may not appear in the WHERE clause unless it is in a subquery contained in a HAVING clause or a select list, and the column being aggregated is an outer reference.

    Read the article

  • Optimizing 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

  • SQL Server Group Concat with Different characters

    - by Molloch
    I have looked through a number of solutions to emulating "Group concat" functionality in SQL Server. I wanted to make a more human readable solution though and I can't work out how to do it. I have a view: ParentID | ChildName Which contains the records, for example: 1 | Max 1 | Jessie 2 | Steven 2 | Lucy 2 | Jake 3 | Mark I want to "Group Concat" these to get: 1 | Max and Jessie 2 | Steven, Lucy and Jake 3 | Mark So If there is only 1 child, just return name, if there are more than one, concat the last 2 with an ' and ' and all others with a ', '. I am a bit stuck on how to do this without resorting to CLR, which I don't want to do. I am happy with a function - but speed is an issue and how do I determine the child number so I can choose between ' and ', ', ' or ''?

    Read the article

  • SQL 2005: Select top N, group by ID with joins

    - by Suzy Fresh
    I'm having real difficulty with a query involving 3 tables. I need to get the 3 newest users per department grouped by department names. The groups should be sorted by the users.dateadded so the department with the newest activity is first. The users can exist in multiple departments so Im using a lookup table that just contains the userID and deptID. My tables are as follows. Department - depID|name Users - userID|name|dateadded DepUsers - depID|userID The output I need would be Receiving John Doe - 4/23/2010 Bill Smith - 4/22/2010 Accounting Steve Jones - 4/22/2010 John Doe - 4/21/2010 Auditing Steve Jones - 4/21/2010 Bill Smith - 4/21/2010

    Read the article

  • SQL Command for the following table.

    - by Sanju
    I have a table named with "Sales" having the following columns: Sales_ID|Product_Code|Zone|District|State|Distributor|Total_Sales Now i want to generate a sales summary to view the total sales by zone and then by district and then by State by which distributor for the last/past month period. How can i write a Sql Statement to do this? Can anyone help me Plz. Thanks in advance. And i have another question that, how can i select the second largest or third largest values from any column of a table.

    Read the article

  • Data Access from single table in sql server 2005 is too slow

    - by Muhammad Kashif Nadeem
    Following is the script of table. Accessing data from this table is too slow. SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[Emails]( [id] [int] IDENTITY(1,1) NOT NULL, [datecreated] [datetime] NULL CONSTRAINT [DF_Emails_datecreated] DEFAULT (getdate()), [UID] [nvarchar](250) COLLATE Latin1_General_CI_AS NULL, [From] [nvarchar](100) COLLATE Latin1_General_CI_AS NULL, [To] [nvarchar](100) COLLATE Latin1_General_CI_AS NULL, [Subject] [nvarchar](max) COLLATE Latin1_General_CI_AS NULL, [Body] [nvarchar](max) COLLATE Latin1_General_CI_AS NULL, [HTML] [nvarchar](max) COLLATE Latin1_General_CI_AS NULL, [AttachmentCount] [int] NULL, [Dated] [datetime] NULL ) ON [PRIMARY] Following query takes 50 seconds to fetch data. select id, datecreated, UID, [From], [To], Subject, AttachmentCount, Dated from emails If I include Body and Html in select then time is event worse. indexes are on: id unique clustered From Non unique non clustered To Non unique non clustered Tabls has currently 180000+ records. There might be 100,000 records each month so this will become more slow as time will pass. Does splitting data into two table will solve the problem? What other indexes should be there?

    Read the article

  • Fastest way to do a weighted tag search in SQL Server

    - by Hasan Khan
    My table is as follows ObjectID bigint Tag nvarchar(50) Weight float Type tinyint I want to get search for all objects that has tags 'big' or 'large' I want the objectid in order of sum of weights (so objects having both the tags will be on top) select objectid, row_number() over (order by sum(weight) desc) as rowid from tags where tag in ('big', 'large') and type=0 group by objectid the reason for row_number() is that i want paging over results. The query in its current form is very slow, takes a minute to execute over 16 million tags. What should I do to make it faster? I have a non clustered index (objectid, tag, type) Any suggestions?

    Read the article

  • sql server procedure optimization

    - by stackoverflow
    SQl Server 2005: Option: 1 CREATE TABLE #test (customerid, orderdate, field1 INT, field2 INT, field3 INT) CREATE UNIQUE CLUSTERED INDEX Idx1 ON #test(customerid) CREATE INDEX Idx2 ON #test(field1 DESC) CREATE INDEX Idx3 ON #test(field2 DESC) CREATE INDEX Idx4 ON #test(field3 DESC) INSERT INTO #test (customerid, orderdate, field1 INT, field2 INT, field3 INT) SELECT customerid, orderdate, field1, field2, field3 FROM ATABLERETURNING4000000ROWS compared to Option: 2 CREATE TABLE #test (customerid, orderdate, field1 INT, field2 INT, field3 INT) INSERT INTO #test (customerid, orderdate, field1 INT, field2 INT, field3 INT) SELECT customerid, orderdate, field1, field2, field3 FROM ATABLERETURNING4000000ROWS CREATE UNIQUE CLUSTERED INDEX Idx1 ON #test(customerid) CREATE INDEX Idx2 ON #test(field1 DESC) CREATE INDEX Idx3 ON #test(field2 DESC) CREATE INDEX Idx4 ON #test(field3 DESC) When we use the second option it runs close to 50% faster. Why is this?

    Read the article

  • SQL Server GROUP BY troubles!

    - by Lucas311
    I'm getting a frustrating error in one of my SQL Server 2008 queries. It parses fine, but crashes when I try to execute. The error I get is the following: Msg 8120, Level 16, State 1, Line 4 Column 'customertraffic_return.company' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause. SELECT * FROM (SELECT ctr.sp_id AS spid, Substring(ctr.company, 1, 20) AS company, cci.email_address AS tech_email, CASE WHEN rating IS NULL THEN 'unknown' ELSE rating END AS rating FROM customer_contactinfo cci INNER JOIN customertraffic_return ctr ON ctr.sp_id = cci.sp_id WHERE cci.email_address <> '' AND cci.email_address NOT LIKE '%hotmail%' AND cci.email_address IS NOT NULL AND ( region LIKE 'Europe%' OR region LIKE 'Asia%' ) AND SERVICE IN ( '1', '2' ) AND ( rating IN ( 'Premiere', 'Standard', 'unknown' ) OR rating IS NULL ) AND msgcount >= 5000 GROUP BY ctr.sp_id, cci.email_address) AS a WHERE spid NOT IN (SELECT spid FROM customer_exclude) GROUP BY spid, tech_email

    Read the article

< Previous Page | 46 47 48 49 50 51 52 53 54 55 56 57  | Next Page >