Search Results

Search found 1369 results on 55 pages for 'where clause'.

Page 9/55 | < Previous Page | 5 6 7 8 9 10 11 12 13 14 15 16  | Next Page >

  • Unexpected behaviour of Order by clause

    - by Newbie
    I have a table which looks like Col1 col2 col3 col4 col5 1 5 1 4 6 1 4 0 3 7 0 1 5 6 3 1 8 2 1 5 4 3 2 1 4 The script is declare @t table(col1 int, col2 int, col3 int,col4 int,col5 int) insert into @t select 1,5,1,4,6 union all select 1,4,0,3,7 union all select 0,1,5,6,3 union all select 1,8,2,1,5 union all select 4,3,2,1,4 If I do a sorting (ascending), the output is Col1 col2 col3 col4 col5 0 1 5 6 3 1 4 0 3 7 1 5 1 4 6 1 8 2 1 5 4 3 2 1 4 The query is Select * from @t order by col1,col2,col3,col4,col5 But as can be seen that the sorting output is wrong (col2 to col5). I want the output to be every column being sorted in ascending order i.e. Col1 col2 col3 col4 col5 0 1 0 1 3 1 3 1 1 4 1 4 2 3 5 1 5 2 4 6 4 8 5 6 7 Why so and how to overcome this? Thanks in advance

    Read the article

  • Where clause on joined table used for user defined key/value pairs

    - by Steve Wright
    Our application allows administrators to add “User Properties” in order for them to be able to tailor the system to match their own HR systems. For example, if your company has departments, you can define “Departments” in the Properties table and then add values that correspond to “Departments” such as “Jewelry”, “Electronics” etc… You are then able to assign a department to users. Here is the schema: In this schema, a User can have only one UserPropertyValue per Property, but doesn’t have to have a value for the property. I am trying to build a query that will be used in SSRS 2005 and also have it use the PropertyValues as the filter for users. My query looks like this: SELECT UserLogin, FirstName, LastName FROM Users U LEFT OUTER JOIN UserPropertyValues UPV ON U.ID = UPV.UserID WHERE UPV.PropertyValueID IN (1, 5) When I run this, if the user has ANY of the property values, they are returned. What I would like to have is where this query will return users that have values BY PROPERTY. So if PropertyValueID = 1 is of Department (Jewelry), and PropertyValueID = 5 is of EmploymentType (Full Time), I want to return all users that are in Department Jewelry that are EmployeeType of Full Time, can this be done? Here's a full data example: User A has Department(Jewelry value = 1) and EmploymentType(FullTime value = 5)User B has Department(Electronics value = 2) and EmploymentType(FullTime value = 5)User C has Department(Jewelry value = 1) and EmployementType(PartTime value = 6) My query should only return User A using the above query UPDATE: I should state that this query is used as a dataset in SSRS, so the parameter passed to the query will be @PropertyIDs and it is defined as a multi-value parameter in SSRS. WHERE UPV.PropertyValueID IN (@PropertyIDs)

    Read the article

  • stored procedure issue, has to do with my where clause and if statement

    - by MyHeadHurts
    right now my stored procedure is returning 2 different result sets one for @booked and the other for @booked1 if you look closely my query is doing the same thing for each @booked and @booked but one is for a user selected year and the other for the current year. I don't want two different result sets, i want to join the selected year and the current year side by side by SDESCR(which is a column that they have in common) another hurdle i am facing is i am use @mode to decide whether the user wants netsales, sales... so on. I know i need sometype of join but, it isnt working because i have a where statement that says where dyyyy= @yeartoget which won't allow the current year data to work ALTER PROCEDURE [dbo].[test1] @mode varchar(20), @YearToGet int AS SET NOCOUNT ON Declare @Booked Int Set @Booked = CONVERT(int,DateAdd(year, @YearToGet - Year(getdate() + 1), DateAdd(day, DateDiff(day, 1, getdate()), 1) ) ) Declare @Booked1 Int Set @Booked1 = CONVERT(int,DateAdd(year, (year( getdate() )) - Year(getdate() + 1), DateAdd(day, DateDiff(day, 1, getdate()), 1) ) ) If @mode = 'Sales' Select Division, SDESCR, DYYYY, Sum(Case When Booked <= @Booked Then NetAmount End) ASofNetSales, SUM(NetAmount) AS YENetSales, Sum(Case When Booked <= @Booked Then PARTY End) AS ASofPAX, SUM(PARTY) AS YEPAX From dbo.B101BookingsDetails Where DYYYY = @YearToGet Group By SDESCR, DYYYY, Division Order By Division, SDESCR, DYYYY else if @mode = 'netsales' Select Division, SDESCR, DYYYY, Sum(Case When Booked <= @Booked Then NetAmount End) ASofNetSales, SUM(NetAmount) AS YENetSales, Sum(Case When Booked <= @Booked Then PARTY End) AS ASofPAX, SUM(PARTY) AS YEPAX From dbo.B101BookingsDetails Where DYYYY = @YearToGet Group By SDESCR, DYYYY, Division Order By Division, SDESCR, DYYYY If @mode = 'Sales' Select Division, SDESCR, DYYYY, Sum(Case When Booked <= @Booked1 Then NetAmount End) currentNetSales, Sum(Case When Booked <= @Booked1 Then PARTY End) AS currentPAX From dbo.B101BookingsDetails Where DYYYY = (year( getdate() )) Group By SDESCR, DYYYY, Division Order By Division, SDESCR, DYYYY else if @mode = 'netsales' Select Division, SDESCR, DYYYY, Sum(Case When Booked <= @Booked1 Then NetAmount End) currentNetSales, Sum(Case When Booked <= @Booked1 Then PARTY End) AS currentPAX From dbo.B101BookingsDetails Where DYYYY = (year( getdate() )) Group By SDESCR, DYYYY, Division Order By Division, SDESCR, DYYYY Else if @mode = 'Inssales' Select Division, SDESCR, DYYYY, Sum(Case When Booked <= @Booked1 Then InsAmount End) currentInsSales, Sum(Case When Booked <= @Booked1 Then PARTY End) AS currentPAX From dbo.B101BookingsDetails Where DYYYY = (year( getdate() )) Group By SDESCR, DYYYY, Division Order By Division, SDESCR, DYYYY

    Read the article

  • how to optimize an oracle query that has to_char in where clause for date

    - by panorama12
    I have a table that contains about 49403459 records. I want to query the table on a date range. say 04/10/2010 to 04/10/2010. However, the dates are stored in the table as format 10-APR-10 10.15.06.000000 AM (time stamp). As a result. When I do: SELECT bunch,of,stuff,create_date FROM myTable WHERE TO_CHAR (create_date,'MM/DD/YYYY)' >= '04/10/2010' AND TO_CHAR (create_date, 'MM/DD/YYYY' <= '04/10/2010' I get 529 rows but in 255.59 seconds! which is because I guess I am doing to_char on EACH record. However, When I do SELECT bunch,of,stuff,create_date FROM myTable WHERE create_date >= to_date('04/10/2010','MM/DD/YYYY') AND create_date <= to_date('04/10/2010','MM/DD/YYYY') then I get 0 results in 0.14 seconds. How can I make this query fast and still get valid (529) results?? At this point I can not change indexes. Right now I think index is created on create_date column

    Read the article

  • Inefficient 'ANY' LINQ clause

    - by Focus
    I have a query that pulls back a user's "feed" which is essentially all of their activity. If the user is logged in the query will be filtered so that the feed not only includes all of the specified user's data, but also any of their friends. The database structure includes an Actions table that holds the user that created the action and a UserFriends table which holds any pairing of friends using a FrienderId and FriendeeId column which map to UserIds. I have set up my LINQ query and it works fine to pull back the data I want, however, I noticed that the query gets turned into X number of CASE clauses in profiler where X is the number of total Actions in the database. This will obviously be horrible when the database has a user base larger than just me and 3 test users. Here's the SQL query I'm trying to achieve: select * from [Action] a where a.UserId = 'GUID' OR a.UserId in (SELECT FriendeeId from UserFriends uf where uf.FrienderId = 'GUID') OR a.UserId in (SELECT FrienderId from UserFriends uf where uf.FriendeeId = 'GUID') This is what I currently have as my LINQ query. feed = feed.Where(o => o.User.UserKey == user.UserKey || db.Users.Any(u => u.UserFriends.Any(ufr => ufr.Friender.UserKey == user.UserKey && ufr.isApproved) || db.Users.Any(u2 => u2.UserFriends.Any(ufr => ufr.Friendee.UserKey == user.UserKey && ufr.isApproved) ))); This query creates this: http://pastebin.com/UQhT90wh That shows up X times in the profile trace, once for each Action in the table. What am I doing wrong? Is there any way to clean this up?

    Read the article

  • Enums With Default Throw Clause?

    - by Tom Tresansky
    I noticed the following in the Java Language spec in the section on enumerations here: link switch(this) { case PLUS: return x + y; case MINUS: return x - y; case TIMES: return x * y; case DIVIDE: return x / y; } throw new AssertionError("Unknown op: " + this); However, looking at the switch statement definition section, I didn't notice this particular syntax (the associated throw statement) anywhere. Can I use this sort of "default case is throw an exception" syntactic sugar outside of enum definitions? Does it have any special name? Is this considered a good/bad practice for short-cutting this behavior of "anything not in the list throws an exception"?

    Read the article

  • sql insert statement with a lot of same where clause and one different where cluase

    - by william
    I m sry if the title is not clear. Here's my proble. I created a new table which will show total, average and maximum values. I have to insert the results into that table. That table will have only 4 rows. No Appointment, Appointment Early, Appointment Late and Appointment Punctual. So.. I have sth like.. insert into newTable select 'No Appointment' as 'Col1', avg statement, total statement, max statement from orgTable where (general conditions) and (unique condition to check NO APPOINTMENT); I have to do that same thing for another 3 rows.. where only the unique condition is different to check early, punctual or late.. So..the statement is super long. I wanna reduce the size.. How can I achieve that?

    Read the article

  • NHibernateUtil.Initialize and Table where clause (Soft Delete)

    - by Pascal
    We are using NHibernate but sometimes manually load proxies using the NHibernateUtil.Initialize call. We also employ soft delete and have a "where" condition on all our mapping to tables. SQL generated by NHibernate successfully adds the where condition (i.e. DELETED IS NULL) however we notice that NHibernateUtil.Initialize does not observe the constraints of the mapping files. i.e. None of the SQL generated by NHibernateUtil.Initialize observes our DELETED IS NULL condition. Is there something we're missing as we would really like to employ manual loading of some entity collections when the situation demands it. We are using FluentNhibernate for our mapping.

    Read the article

  • MySQL : delete from table that is used in the where clause

    - by Eric
    I am writing a small script to synchronize 2 MySQL tables ( t1 to be 'mirrored' to t2 ) In a step I would like to delete rows inside t2 that has been delete in t1 with the same id. I tried this query : delete from t2 where t2.id in ( select t2.id left join t1 on (t1.id=t2.id) where t1.id is null ) But Mysql forbid me to use t2 in the same time in the delete and in the select (sound logical by the way) Of course, I can split the query into 2 queries : first select IDs, then delete rows with these IDs. My question : do you have a cleaner way to delete row from t2 that does not exist anymore in t1 ? with one query only ?

    Read the article

  • IS NULL vs = NULL in where clause + SQL Server

    - by Nev_Rahd
    Hello How to check a value IS NULL [or] = @param (where @param is null) Ex: Select column1 from Table1 where column2 IS NULL => works fine If I want to replace comparing value (IS NULL) with @param. How can this be done Select column1 from Table1 where column2 = @param => this works fine until @param got some value in it and if is null never finds a record. How can this achieve?

    Read the article

  • JavaScript: If clause partially executed !!!

    - by arwa
    Hi everyone My problem is that when the condition is true it will close the window but not execute the php part ! here goes my code.. function onClose() { var r=confirm("Is the meeting Over!"); if (r==true) { window.close(); } else { } } </blink> this is the php part.. $sql="UPDATE previousmeetings SET Live='0' WHERE MeetingID='34'"; //$meeting_id $sql2="UPDATE previousmeetings SET Live='1' WHERE MeetingID='34'";

    Read the article

  • Get result from mysql orderd by IN clause

    - by SchlaWiener
    I have the following query SELECT * FROM invoice WHERE invoice_id IN (13, 15, 9, 27) My result is: invoice_id | invoice_number | ... ------------------------------------ 9 | 201006003 | 13 | 201006020 | 15 | 201006022 | 27 | 201006035 | which is the result set I want except that is ordered by the invoice_id (which is an autoincrement value). Now I want the result in the order I specified in my query (13, 15, ...). Is there a way to achive that? The background is that I have a DataTable bound to a DataGridView. The user can filter and sort the result but if he want's to print the result I don't use the DataTable for printing because it only contains the most important columns and instead I pull the whole records from the database and pass it to my printing control. I also tried to extend the existing DataTable with the missing results but that seems to slower than using the IN (...) query.

    Read the article

  • problem adding a where clause to a T-sql LEFT OUTER JOIN query

    - by Nickson
    SELECT TOP (100) PERCENT dbo.EmployeeInfo.id, MIN(dbo.EmployeeInfo.EmpNo) AS EmpNo, SUM(dbo.LeaveApplications.DaysAuthorised) AS DaysTaken FROM dbo.EmployeeInfo LEFT OUTER JOIN dbo.LeaveApplications ON dbo.EmployeeInfo.id = dbo.LeaveApplications.EmployeeID WHERE (YEAR(dbo.LeaveApplications.ApplicationDate) = YEAR(GETDATE())) GROUP BY dbo.EmployeeInfo.id, dbo.EmployeeMaster.EmpNo ORDER BY DaysTaken DESC The basic functionality i want is to retrieve all records in table dbo.EmployeeInfo irrespective of whether a corresponding record exists in table dbo.LeaveApplications. If a row in EmployeeInfo has no related row in LeaveApplications, i want to return its SUM(dbo.LeaveApplications.DaysAuthorised) AS DaysTaken column as NULL or may be even put a 0. With the above query, if i remove the where condition, am able to achieve what i want, but problem is i also want to return related rows from LeaveApplication only if ApplicationDate is in the current year. Now with the where condition added, am only able to get rows from EmployeeInfo only if they have corresponding rows in LeaveApplications yet i just wanted rows all in EmployeeInfo

    Read the article

  • Complicated Order By Clause?

    - by Todd
    Hi. I need to do what to me is an advanced sort. I have this two tables: Table: Fruit fruitid | received | basketid 1 20100310 2 2 20091205 3 3 20100220 1 4 20091129 2 Table: Basket id | name 1 Big Discounts 2 Premium Fruit 3 Standard Produce I'm not even sure I can plainly state how I want to sort (which is probably a big part of the reason I can't seem to write code to do it, lol). I do a join query and need to sort so everything is organized by basketid. The basketid that has the oldest fruit.received date comes first, then the other rows with the same basketid by date asc, then the basketid with the next earliest fruit.received date followed by the other rows with the same basketid, and so on. So the output would look like this: Fruitid | Received | Basket 4 20091129 Premuim Fruit 1 20100310 Premuim Fruit 2 20091205 Standard Produce 3 20100220 Big Discounts Any ideas how to accomplish this in a single execution?

    Read the article

  • Unexpected behaviour of Order by clause(SQL SERVER 2005)

    - by Newbie
    I have a table which looks like Col1 col2 col3 col4 col5 1 5 1 4 6 1 4 0 3 7 0 1 5 6 3 1 8 2 1 5 4 3 2 1 4 The script is declare @t table(col1 int, col2 int, col3 int,col4 int,col5 int) insert into @t select 1,5,1,4,6 union all select 1,4,0,3,7 union all select 0,1,5,6,3 union all select 1,8,2,1,5 union all select 4,3,2,1,4 If I do a sorting (ascending), the output is Col1 col2 col3 col4 col5 0 1 5 6 3 1 4 0 3 7 1 5 1 4 6 1 8 2 1 5 4 3 2 1 4 The query is Select * from @t order by col1,col2,col3,col4,col5 But as can be seen that the sorting output is wrong (col2 to col5). Why so and how to overcome this? Thanks in advance

    Read the article

  • mySQL: Can I make count() honor limit clause?

    - by Stomped
    I'm trying to get a count of records matching certain criteria within a subset of the total records. I tried (and assumed this would work) SELECT count(*) FROM records WHERE status = 'ADP' LIMIT 0,10 and I assumed this would tell me how many records of status ADP were in that set of 10 records. It doesn't - it returns, in this case 30, which is the total number of ADP records in the table. How do I just count up the records matching my criteria including the limit?

    Read the article

  • SQL Select for multiple where clause

    - by Tony
    Hi, I am trying to create SQL Select that returns counts of a certain field based on a field. So, here is what I am trying to do. Select count(distinct id) as TotalCount, -- this will be the total of id count(distinct id where type='A') as TotalA, -- this will be total when type='A' count(distinct id where type='B') as TotalB -- This will be total when type = 'B' from MyTable Basically, TotalCount = TotalA + TotalB. How can I achieve this in SQL Select Statement? Thanks.

    Read the article

  • Stopping an if clause along with the whole PHP script, but not HTML

    - by user626816
    Hello there, I've been having this problem for around an hour, and have searched the internet for answers. I've checked the PHP documentation, looked around, Googled, nothing. Anyways, my problem is that after I try to validate something (and it's wrong), if I use exit; it will also stop the HTML after. Here's what I'm talking about: if ($_POST['exampleEmail'] == "") { echo "Please enter an e-mail."; //Now I want only the PHP script to stop, however... exit; //If I use exit, then the HTML after this script (footer) doesn't show. } If anyone can help, please do. I've tried using break, but to no avail, since it's only for loops and switches. If there is a better/more correct (or simply correct if this is the wrong way), please share. I've had this problem in the past, and I just used exit then. Thanks.

    Read the article

  • SQL use comma-separated values with IN clause

    - by user342944
    I am developing an ASP.NET application and passing a string value like "1,2,3,4" into a procedure to select those values which are IN (1,2,3,4) but its saying "Conversion failed when converting the varchar value '1,2,3,4' to data type int." Here is the aspx code: private void fillRoles() { /*Read in User Profile Data from database */ Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetStoredProcCommand("sp_getUserRoles"); db.AddInParameter(cmd, "@pGroupIDs", System.Data.DbType.String); db.SetParameterValue(cmd, "@pGroupIDs", "1,2,3,4"); IDataReader reader = db.ExecuteReader(cmd); DropDownListRole.DataTextField = "Group"; DropDownListRole.DataValueField = "ID"; while (reader.Read()) { DropDownListRole.Items.Add((new ListItem(reader[1].ToString(), reader[0].ToString()))); } reader.Close(); } Here is my procedure: CREATE Procedure [dbo].[sp_getUserRoles](@pGroupIDs varchar(50)) AS BEGIN SELECT * FROM CheckList_Groups Where id in (@pGroupIDs) END

    Read the article

  • SQL Server - Searching string with international characters using LIKE clause

    - by Nikhil
    Hi, I have a field 'Description' which can have product descriptions with any unicode characters. If I search for a description which contains an international character, with a LIKE condition (word searched with does not have the international character) I get the following results: Ex: GEWÜRZTRAMINER is one of the descriptions. When I do: Select * from table where Description LIKE '%GEWURZTRAMINER%', it retrieves the entry. When I do: Select * from table where Description LIKE '%GEWURZ%', the entry is not retrieved. (Note: the search condition does not include the Ü but has a U) Is there a way around this so that I can retrieve with '%GEWURZ%' as well? SQl Server 2008

    Read the article

  • Performance improvement to a big if clause in SQL Server function

    - by Miles D
    I am maintaining a function in SQL Server 2005, that based on an integer input parameter needs to call different functions e.g. IF @rule_id = 1 -- execute function 1 ELSE IF @rule_id = 2 -- execute function 2 ELSE IF @rule_id = 3 ... etc The problem is that there are a fair few rules (about 100), and although the above is fairly readable, its performance isn't great. At the moment it's implemented as a series of IF's that do a binary-chop, which is much faster, but becomes fairly unpleasant to read and maintain. Any alternative ideas for something that performs well and is fairly maintainable?

    Read the article

  • Group by clause return latest row information

    - by I Like PHP
    below is my table structure table_movie_info i_movie_id |movie_actor_id |movie_actress_id |movie_director_id | movie_producer_id 48 | 5 | 9 | 66 | 21 48 | 6 | 15 | 88 | 22 48 | 7 | 12 | 77 | 23 one more table is table_movie movie_id | movie_year | movie_genre_id |movie_rating 1 | 2009 | 6 | 8 2 | 2001 | 5 | 7.5 48 | 2007 | 3 | 6.8 now i need total movie information using both table,i write below query SELECT * FROM table_movie_info LEFT JOIN table_movie ON movie_id = i_movie_id WHERE i_movie_id=48 GROUP BY i_movie_id above query return only one row , but i need such type of information movie_id=48, actors_id list=5,6,7 acttress_id list=9,15,12 etc.. please tell me the optimized query which h return complete information i need. thanks for helping me always.

    Read the article

  • PreparedStatement and 'null' value in WHERE clause

    - by bond
    I am using PrepareStatement and BatchUpdate for executimg a UPDATE query. In for loop I create a Batch. At end of loop I execute batch. Above logic works fine if SQL query used in PrepareStatement does not have null values in WHERE claues. Update Statement fails if there is null value in WHERE clasue. My code looks something like this, connection = getConnection(); PreparedStatement ps = connection.prepareStatement("UPDATE TEST_TABLE SET Col1 = true WHERE Col2 = ? AND Col3 = ?") for (Data aa : InComingData) { if(null == aa.getCol2()) { ps.setNull(1, java.sql.Types.INTEGER); } else { ps.setInteger(1,aa.getCol2()) } if(null == aa.getCol3()) { ps.setNull(2, java.sql.Types.INTEGER); } else { ps.setInteger(2,aa.getCol3()) } ps.addBatch(); } ps.executeBatch(); connection.commit(); Any help would be appreciated.

    Read the article

< Previous Page | 5 6 7 8 9 10 11 12 13 14 15 16  | Next Page >