Search Results

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

Page 39/55 | < Previous Page | 35 36 37 38 39 40 41 42 43 44 45 46  | Next Page >

  • Does any language have a while-else flow structure?

    - by dotancohen
    Consider this flow structure which I happen to use often: if ( hasPosts() ) { while ( hasPosts() ) { displayNextPost(); } } else { displayNoPostsContent(); } Are there any programming languages which have an optional else clause for while, which is to be run if the while loop is never entered? Thus, the code above would become: while ( hasPosts() ) { displayNextPost(); } else { displayNoPostsContent(); } I find it interesting that many languages have the do-while construct (run the while code once before checking the condition) yet I have never seen while-else addressed. There is precedent for running an N block of code based on what was run in N-1 block, such as the try-catch construct. I wasn't sure whether to post here or on programmers.SE. If this question is more appropriate there, then please move it. Thanks.

    Read the article

  • Using AND/OR mysql commands with FROM_UNIXTIME

    - by scatteredbomb
    Trying to select a query in php/mysql to get "Upcoming Items" in a calendar. We store the dates in the DB as a unix time. Here's what my query looks like right now SELECT * FROM `calendar` WHERE (`eventDate` > '$yesterday') OR (FROM_UNIXTIME(eventDate, '%m') > '$current_month' AND `$yearly` = '1') ORDER BY `eventDate` LIMIT 4 This is giving me an error "Unknown column '' in 'where clause'". I'm sure it has to do with my use of parenthesis (which I've never used before in a query) and the FROM_UNIXTIME command. Can someone help me out and let me know how I've screwed this up? Thanks!

    Read the article

  • How to dynamically order many-to-many relationship with JPA or HQl?

    - by Indrek
    I have a mapping like this: @ManyToMany(cascade = CascadeType.PERSIST) @JoinTable( name="product_product_catalog", joinColumns={@JoinColumn(name="product_catalog", referencedColumnName="product_catalog")}, inverseJoinColumns={@JoinColumn(name="product", referencedColumnName="product")}) public List<Product> products = new ArrayList<Product>(); I can fetch the products for the catalog nicely, but I can't (dynamically) order the products. How could I order them? I probably have to write a many-to-many HQL query with the order-by clause? I though of passing the orderBy field name string to the query, or is there a better solution? Tables are: products, product_catalog, product_product_catalog (associative table) P.S. Using Play! Framework JPASupport for my entities.

    Read the article

  • MySQL indexes - what are the best practises?

    - by Haroldo
    I've been using indexes on my mysql databases for a while now but never properly learnt about them. Generally I put an index on any fields that i will be searching or selecting using a WHERE clause but sometimes it doesn't seem so black and white. What are the best practises for mysql indexes? example situations/dilemas: If a table has six columns and all of them are searchable, should i index all of them or none of them? . What are the negetive performance impacts of indexing? . If i have a VARCHAR 2500 column which is searchable from parts of my site, should i index it?

    Read the article

  • Rails Rspec testing not saving a transactional model

    - by NolanDC
    I'm currently testing my Rails controllers using RSpec. In one controller, I have a model that uses transactions, so that it will not be saved unless another nested model (whose data is filled in using fields_for) is also saved correctly. The tests hit a snag when they reach the transaction. Some debugging output proves that the model is valid and ready to save. However, upon entering the transaction block, the model does not save. Even stranger, the code never reaches the else clause of "if model.save" (It does, however, enter the transaction block). I can only assume this is a problem with my testing a transactional model. Any ideas/hints/solutions?

    Read the article

  • Subsonic : Same column name different tables

    - by John Transformer
    Hi, I have a query where I need to do a "Where" clause for two different columns in two different tables but subsonic creates the same parametrized parameter name for both which is causing an issue. How can I fix this? string _RawSql = new Select() .From(Tables.Table1) .InnerJoin(Tables.Table2) .InnerJoin(Table3.SidColumn, Table2.Table3SidColumn) .Where(Table1.SidColumn).IsEqualTo(2) .And(Table3.SidColumn).IsEqualTo(1) .BuildSqlStatement(); The query this is creating is SELECT .... FROM [dbo].[Table1] INNER JOIN [dbo].[Table2] ON [dbo].[Table1].[Table2Sid] = [dbo].[Table2].[Sid] INNER JOIN [dbo].[Table3] ON [dbo].[Table2].[Table3Sid] = [dbo].[Table3].[Sid] WHERE [dbo].[Table1].[Sid] = @Sid AND [dbo].[Table3].[Sid] = @Sid Note that in the last two lines its using @Sid for both Table1 and Table3. How go I do it so it uses @Sid0 and @Sid1? Any help would be appreciated. Thanks

    Read the article

  • How to update a record with multiple keys

    - by OceanBlue
    I am trying a database app on Android. I want to use the SQLiteDatabase update(...) convenience method to update a record. Normally, for a WHERE clause of a single key this is working. Following code is working fine:- values.put("testname", "Quiz1"); mDB.update("Tests", values, "id=?", new String[]{"2"}); //this statement works However, I want to update a column in a table which has a combination of two keys as the unique identifier. I tried the following. This executes without exception, but nothing is updated. values.put("score", 60); mDB.update("Results", values, "studentid=? AND testid=?", new String[] { "2,1" }); // this statement does not work How to do it?

    Read the article

  • MySQL Limiting a query to one consistent value

    - by Lucas Matos
    My current query returns a table like: +------------+ value1 | .... value1 | .... value2 | .... value3 | .... +------------+ I want: +------------+ value1 | .... value1 | .... +------------+ I want to only receive all rows with the first value. Normally I would do a WHERE clause if I knew that value, and I cannot use a LIMIT because each value has a different number of rows. Right now My query looks like "SELECT u.*, n.something, w.* FROM ... AS u, ... AS n, ... AS w WHERE u.id = n.id AND w.val = n.val AND u.desc LIKE '%GET REQUEST VARIABLE%';" This works great, except I get way too many rows and using PHP to do this ruins code portability and is superfluous. Thanks for reading

    Read the article

  • mysql - check if data exists across multiple tables

    - by Dd Daym
    I am currently running this query inside MySQL to check if the specified values exists within the table associated with them. SELECT COUNT(artist.artist_id), COUNT(album.album_id), COUNT(tracks.track_id) FROM artist, album, tracks WHERE artist.artist_id = 320295 OR album.album_id = 1234 OR tracks.track_id = 809 The result I get from running this query is all 1, meaning that all the statements after the WHERE clause is true. To further check the query's reliability, I changed the tracks.track_ = 809 to 802, which I know does not match. However the results displayed are still all 1, meaning that they were all successfully matched even when I purposefully inserted a value which would not have matched. How do I get it to show 1 for a match and 0 for no matches within the same query? EDIT: I have inserted an image of the query running

    Read the article

  • MySQL COUNT help

    - by space
    I'm trying to count all the ids form table3 that are related to the first two tables but I think my SQL code is wrong can some one help me fix it? Here is the code: $dbc = mysqli_query($mysqli,"SELECT table1.*, table2.*, COUNT(id) as num, table3.id FROM table1 INNER JOIN table2 ON table1.id = table2.id INNER JOIN table3 ON table2.id = table3.id WHERE table2.id = '$id'"); Here is the error message. Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 4

    Read the article

  • SQL Server 2008 - Conditional Query

    - by Villager
    Hello, SQL is not one of my strong suits. I have a SQL Server 2008 database. This database has a stored procedure that takes in eight int parameters. For the sake of keeping this question focused, I will use one of these parameters for reference: @isActive int Each of these int parameters will be -1, 0, or 1. -1 means "Unknown" or "Don't Care". Basically, I need to query a table such that if the int parameter is NOT -1, I need to consider it in my WHERE clause. Because there are eight int parameters, an IF-ELSE statement does not seem like a good idea. At the same time, I do not know how else to do this? Is there an elegant way in SQL to add a WHERE conditional if a parameter does NOT equal a value? Thank you!

    Read the article

  • Delay and Inconsistent results using Twitter search API when using "since_id" parameter.

    - by benr
    Hi. We've noticed what seems to be a delay and/or inconsistent results using the Twitter Search API when specifying a sinceid in the param clause. For example: http://search.twitter.com/search?ors=%23b4esummit+@b4esummit+b4esummit&q=&result_type=recent&rpp=100&show_user=true&since_id= Will give the most recent Tweets, but: http://search.twitter.com/search?ors=%23b4esummit+@b4esummit+b4esummit&q=&result_type=recent&rpp=100&show_user=true&since_id= 12642940173 will often not give tweets that are after that ID for several hours (even though they're visible in the first query)... anyone have similar problems?

    Read the article

  • [C++] Boost test: catch user defined exceptions

    - by user231536
    If I have user defined exceptions in my code, I can't get Boost test to consider them as failures. For example, BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES(MyTest,1) BOOST_AUTO_TEST_CASE(MyTest) { // code which throws user defined exception, not derived from std::exception. } I get a generic message: Caught exception: .... unknown location(0):.... It does not recognize this error as a failure since it is not a std::exception. So it does not honor the expected_failures clause. How do I enforce that the piece of code should always throw an exception? THis seems to be a useful thing to want. In case future code changes cause the code to pass and the exception is not thrown, I want to know that.

    Read the article

  • Why is my left join not returning nulls?

    - by Griz
    In sql server 2008, I have the following query: select c.title as categorytitle, s.title as subcategorytitle, i.title as itemtitle from categories c join subcategories s on c.categoryid = s.categoryid left join itemcategories ic on s.subcategoryid = ic.subcategoryid left join items i on ic.itemid = i.itemid where (ic.isactive = 1 or ic.isactive is null) and i.siteid = 132 order by c.title, s.title I am trying to get items in their subcategories, but I still want to return a record if there are no items in the category or subcategory. Subcategories that have no items are never returned. What am I doing wrong? Thank you EDIT Modified query with a second left join and where clause, but it's still not returning nulls. :/

    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

  • Problems with ActiveRecord assoc

    - by ciss
    Hello again, so i write my e-commerce shop cms and have some strange error: ActiveRecord::StatementInvalid: Mysql::Error: Unknown column 'id' in 'where clause': DELETE FROM `properties` WHERE `id` = NULL so, i have three models Items: class Item < ActiveRecord::Base has_many :properties, :dependent => :destroy has_many :types, :through => :property end Type: class Type < ActiveRecord::Base has_many :properties, :dependent => :destroy end Properties: class Property < ActiveRecord::Base belongs_to :item belongs_to :type end So, all is okay, but when i try to item.destroy() i have error =( This is my test code: test "should destroy associated properties" do item = Item.create(:name => "Jeans") type = Type.create(:key => "color") property = Property.new property.item = item property.type = type property.save item.destroy() end

    Read the article

  • table changes depending on ddl values with servlet

    - by kawtousse
    I will be more clear. What I want to realize is the following: In a JSP x I have a 3 dropdownlists and a button called edit when user click this button a table dynamically should be displayed. Now this table is modified correponding the values in those 3 ddl. So it can be 3 cols or 4 cols or even 6 cols it depends on the selected values. So what I tried is to use the servlet to getParameter doing the if clause construct the html and then forward the response.Have you any the suggestion of the structure that I can use. Think you.

    Read the article

  • SQL query not working

    - by Ziv
    hi, I'm trying to create a query in an access database for a C# dataset using the query editor but the created method says there is a problem and isn't created correctly. SELECT Discs.* FROM Discs WHERE (Title=@Title OR @Title IS NULL) AND (Type=@Type OR @Type IS NULL) AND (ContainerID=@ContainerID OR @ContainerID IS NULL) AND NOT (@Title IS NULL AND @Type IS NULL AND @ContainerID IS NULL) the error is: Generated SELECT statement. Error in WHERE clause near '@'. Unable to parse query text. the generated select method doesn't have any parameters and is unusable. I've tried the exact same SQL statement in the access query and it worked flawlessly, what am I supposed to be doing differently when transferring it to C#?

    Read the article

  • Select rows where column LIKE dictionary word

    - by Gerve
    I have 2 tables: Dictionary - Contains roughly 36,000 words CREATE TABLE IF NOT EXISTS `dictionary` ( `word` varchar(255) NOT NULL, PRIMARY KEY (`word`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; Datas - Contains roughly 100,000 rows CREATE TABLE IF NOT EXISTS `datas` ( `ID` int(11) NOT NULL AUTO_INCREMENT, `hash` varchar(32) NOT NULL, `data` varchar(255) NOT NULL, `length` int(11) NOT NULL, `time` int(11) NOT NULL, PRIMARY KEY (`ID`), UNIQUE KEY `hash` (`hash`), KEY `data` (`data`), KEY `length` (`length`), KEY `time` (`time`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=105316 ; I would like to somehow select all the rows from datas where the column data contains 1 or more words. I understand this is a big ask, it would need to match all of these rows together in every combination possible, so it needs the best optimization. I have tried the below query, but it just hangs for ages: SELECT `datas`.*, `dictionary`.`word` FROM `datas`, `dictionary` WHERE `datas`.`data` LIKE CONCAT('%', `dictionary`.`word`, '%') AND LENGTH(`dictionary`.`word`) > 3 ORDER BY `length` ASC LIMIT 15 I have also tried something similar to the above with a left join, and on clause that specified the like statement.

    Read the article

  • pass parameter from controller to models condition

    - by Alex
    I'm trying to bind a param to a join via a named scope., but I'm getting an error. What is the correct way to do that? has_one :has_voted, :class_name => 'Vote', :conditions => ['ip = :userIp'] # named scopes scope :with_vote, lambda {|ip| { :include => [:has_voted], # like this ?? :conditions => [:has_voted => {:conditions => {:userIp => ip}} ] }} Idea.with_vote(request.ip).all I believe I need the condition definition in the model for it to appear in the ON clause of a JOIN, rather then in the WHERE one. Edit I'm trying to get the following query select Ideas.*, Votes.* from Ideas left outer join Votes on Votes.Idea_id = Idea.id AND Votes.ip = {request.ip}

    Read the article

  • SQL finding overlapping of times pass midnight (across 2 days)

    - by janechii
    Hi everyone, I know there are lots of these types of questions, but i didn't see one that was similar enough to my criteria. So i'd like to ask for your help please. The fields i have are just start and end which are of time types. I cannot involve any specific dates in this. If the time ranges don't go pass midnight across day, i'd just compare two tuples as such: end1 > start2 AND start1 < end2 (end points touching are not considered overlapped here.) But when I involve time range that pass (or at) midnight, this obviously doesn't work. For example, given: start | end --------+-------- 06:00PM | 01:00AM 03:00PM | 09:00PM Without involving dates, how can i achieve this, please. My assumption is, if end is less than start, then we're involving 2 days. I'm trying to do this in plain standard SQL, so just a simple and concise logic in the WHERE clause. Thank you everyone!

    Read the article

  • Query to return substring from string in SQL Server

    - by Jowie
    I have a user defined function called Sync_CheckData under Scalar-valued functions in Microsoft SQL Server. What it actually does is to check the quantity of issued product and balance quantity are the same. If something is wrong, returns an ErrorStr nvarchar(255). Output Example: Balance Stock Error for Product ID : 4 From the above string, I want to get 4 so that later on I can SELECT the rows which is giving errors by using WHERE clause (WHERE Product_ID = 4). Which SQL function can I use to get the substring?

    Read the article

  • Optimal search queries

    - by Macros
    Following on from my last question http://stackoverflow.com/questions/2788082/sql-server-query-performance, and discovering that my method of allowing optional parameters in a search query is sub optimal, does anyone have guidelines on how to approach this? For example, say I have an application table, a customer table and a contact details table, and I want to create an SP which allows searching on some, none or all of surname, homephone, mobile and app ID, I may use something like the following: select * from application a inner join customer c on a.customerid = a.id left join contact hp on (c.id = hp.customerid and hp.contacttype = 'homephone') left join contact mob on (c.id = mob.customerid and mob.contacttype = 'mobile') where (a.ID = @ID or @ID is null) and (c.Surname = @Surname or @Surname is null) and (HP.phonenumber = @Homphone or @Homephone is null) and (MOB.phonenumber = @Mobile or @Mobile is null) The schema used above isn't real, and I wouldn't be using select * in a real world scenario, it is the construction of the where clause I am interested in. Is there a better approach, either dynamic sql or an alternative which can achieve the same result, without the need for many nested conditionals. Some SPs may have 10 - 15 criteria used in this way

    Read the article

  • jQuery - How to determine if a parent element exists?

    - by Dan
    Hi, I'm trying to dynamically and a link to an image, however I cannot correctly determine is the parent link already exists. This is what I have, if (element.parent('a'.length) > 0) { element.parent('a').attr('href', link); } else { element.wrap('<a></a>'); element.parent('a').attr('href', link); } Where element refers to my img element and link refers to the url to use. Every time the code runs, the else clause is performed, regardless of whether or not the img tag is wrapped in an a tag. Can anyone see what I'm doing wrong? Any advice appreciated. Thanks.

    Read the article

  • Occasional conversion error using SUM function

    - by user153777
    My app uses sql2000 and a select statement it uses will sometimes fail. Once a week or so the select returns the error 'Error Converting data type varchar to numeric' SQL: sum(case when ISNULL(form_prsn_id, -1) = irpd_prsn_id then convert(dec(11,2), case when valu_value = '' then '0' else isnull (valu_value,'0') end)* case when fmdt_deduction_flag = 'Y' then -1 else 1 end else 0 end) as client_sum The valu_value field is a varchar and stores some numeric and some varchar. But including my join and where clause filter it will always select numeric or empty string. When it is failing I can remove the SUM, see the data and know that its numeric. So why would the SUM function sometimes (say 5% of time) fail on data that is numeric. I wonder if SQL somehow "looks ahead" to ensure it could convert to decimal on more than just the rows returned without the sum. Note I have discovered a fix where I include ( where isNumeric(valu_value) = 1 ) Thanks

    Read the article

< Previous Page | 35 36 37 38 39 40 41 42 43 44 45 46  | Next Page >