sql

MySQL: How to add one day to datetime field in query

Hello, In my table I have a field named eventdate in datetime format like 2010-05-11 00:00:00. How do i make a query so that it adds one day to the eventdate eg if today is 2010-05-11, i want to show in where clause to return all records with tomorrow's date. Update: I tried this: select * from fab_scheduler where custid = 133466605...

sql swap primary key values

Hi, is it possible to swap primary key values between two datasets? If so, how would one do that? ...

Hibernate Criteria API: get n random rows

I can't figure out how to fetch n random rows from a criteria instance: Criteria criteria = session.createCriteria(Table.class); criteria.add(Restrictions.eq('fieldVariable', anyValue)); ... Then what? I can't find any doc with Criteria API Does it mean I should use HQL instead? Thanx! EDIT: I get the number of rows by: int max =...

mysql query clarification

I have a query which I am wondering if the result I am getting is the one that I am expecting. The table structure goes like this : Table : results ID TestCase Set Analyzed Verdict StartTime Platform 1 1010101 ros2 false fail 18/04/2010 20:23:44 P1 2 1010101 ros3 false fail 19/04/2010 22:22:33 P...

SQL Loop over a family tree

Using SQL server 2008. I have a family tree of animals stored in a table, and want to give some information on how 'genetically diverse' (or not) the offspring is. In SQL how can I produce sensible metrics to show how closely related the parents are? Perhaps some sort of percentage of shared blood, or a number of generations to go back b...

How to analyze 'dbcc memorystatus' result in SQL Server 2008

Currently i am facing a sql memory pressure issue. i have run 'dbcc memorystatus', here is part of my result: Memory Manager KB ---------------------------------------- ----------- VM Reserved 23617160 VM Committed 14818444 Locked Pages Allocated ...

Oracle - Parameterized Query has EXECUTIONS = PARSE_CALLS

We have a .NET application talking to Oracle 10g. Our DBA recently pulled a list of queries where executions is equal to parse_calls. We assumed that this would help us find all of the unparameterized queries in our code. Unexpectedly, the following query showed up near the top of this list, with 1,436,169 executions and 1,436,151 par...

In a stored procedure how to run a query and conditionally do something

How would I do this in a stored procedure (SQL 2005): count = select count(*) from table1 where line like '%success%' if count > 0: delete from table1 where not line like '%success%' Thanks for any help. My google skills are really failing me today :-( ...

Setting SQL Relationships For LINQ Queries

I have two tables that I'm trying to create a relationship between so I can write nice LINQ queries that don't require join. Widgets WidgetId WidgetDescription Orders OrderId WidgetId OrderDate What I want to be able to do is create a LINQ query that does something similar to: var result = from x in db.Widgets Where x.Orders.Order...

mysQL Query help regarding find text

Hello, I need to get all rows in which eventname field contains this text (including single quote) 's Birthday I tried this but it is giving error: select * from fab_scheduler where eventname like '%\'s Birthday%' How do i construct such query? Thanks ...

concatenating results from SQL query and NULL columns

I need to concatenate several columns of a table into a single value, then show that value in an asp dropdownlist. The SQL code I'm issuing is as follows: SELECT UserID, CustomerNum, UserName + ' - ' + UserAddress + ',' + UserCity + ' ' + UserState AS UserInfo FROM Users WHERE (CustomerNum = @CustomerNum) ORDER BY Use...

Retrieving multiple rows in SQL Server but distinct filtering only on one

I have this: SELECT Product.ProductID, Product.Name, Product.GroupID, Product.GradeID, AVG(tblReview.Grade) AS Grade FROM Product left Join tblReview ON Product.GroupID = tblReview.GroupID WHERE (Product.CategoryID = @CategoryID) GROUP BY Product.ProductID, Product.Name, Product.GroupID, Product.GradeID I would like to retu...

Help for a Sql statement

Hy at all, today is the day of ...question. I've a single table, with a relation master-detail like this: RecordID MasterID Field1 Field2 .... NrDetail 1 0 xxx yyyy 1 2 0 aaaa bbbb 2 3 1 hhhhh ssss 0 4 2 eee sssss 0 5 ...

Update Empty XML Tag in SQL Server

I'm trying to update an empty XML Tag in my Xml string on sql server; it says the row is updated when i run the following script, but when I view the XML; nothing has changed: Declare @newValue varchar(100) select @newValue = '01' update dbo.UploadReport set XmlTest.insert('replace value of (/CodeFiveReport/Owner/AgencyID/text(...

Why does my count(*) query time out but the inline view whose records it is counting does not?

Can't figure this one out... when I execute a select query it shows an explain plan cost of ~4500 and takes ~3 seconds to return. When I wrap that query (no changes) inside of: select count(*) from ( /*query here*/ ) It times out. It's at 5 minutes and counting now. I tried this in SQL Developer and Aqua Data Studio -- same result...

C# - InvalidCastException when fetching double from sqlite

I keep getting a InvalidCastException when I'm fetching any double from my SQLite database in C#. The exception says "Specified cast is not valid." I am able to see the value in a SQL manager so I know it exists. It is possible to fetch Strings (VARCHARS) and ints from the database. I'm also able to fetch the value as an object but then...

Diagram a New Database for an ASP.NET Application?

I'm about to create a new application - somewhat like a CRM. I'm thinking it would be best to diagram out all the tables/fields before I begin...but not sure what is the best way to do so? Are there tools in VS? MSSMS? Something else? I want to quickly and thoroughly create the database the application will use for its back-end. ...

How to determine if DataGridView contains uncommitted changes when bound to a SqlDataAdapter

I have a form which contains a DataGridView, a BindingSource, a DataTable, and a SqlDataAdapter. I populate the grid and data bindings as follows: private BindingSource bindingSource = new BindingSource(); private DataTable table = new DataTable(); private SqlDataAdapter dataAdapter = new SqlDataAdapter("SELECT * FROM table ORDER BY id ...

conditional statement in sql server 2k5

How would I filter this query to NOT show any items where "discontinued =1" and quantity=0"? I don't want to exclude all items with a value of discontinued =1. This only applies if the item has the value of discontinued=1 and the quantity =0. select sku,producttitle,location,pt_type as type, vendor_name, active,pricestatus, disc a...

access: sql statement is not sorting for some reason

my report is generating data that is supposed to be sorted by date and is within a specified date range: SELECT * FROM [lab occurrence form] WHERE ((([lab occurrence form].[occurrence date]) Between [Forms]![Form1]![Text2] And [Forms]![Form1]![Text4])) ORDER BY [lab occurrence form].[occurrence date] DESC; i have two textboxes which c...