query

C# CLR Assembly Query

I am creating a C# assembly for MS SQL Server 2005 for encryption/decryption. I need to query the database in this assembly, and was wondering what the preferred method of connecting to the database is? I believe we would not want to have a username/password in the connection string. Since the assembly is registered in MS SQL does it h...

VB XML query on attributes using LINQ

I'm trying to learn LINQ and have a question on querying XML using VB. My XML: <Procedure-Text> <A ID="marker1"></A>Do This Procedure </Procedure-Text> <Procedure-Text> <A ID="marker2"></A>Do That Procedure </Procedure-Text> How can I specify my query to get only the procedure text that has the ID attribute marker2? In ot...

How to make single where condition for this SQL query?

I am using MSSQL 2005 Server and I have the following SQL query. IF @CategoryId IN (1,2,3) BEGIN INSERT INTO @search_temp_table SELECT * FROM (SELECT d.DataId, (SELECT [Name] FROM Category WHERE CategoryId = d.CategoryId) AS 'Category', d.Description, d.CompanyName, d.City, d.CategoryId, d.CreatedOn, d.Rank, d.vot...

AppEngine: Query datastore for records with <missing> value

I created a new property for my db model in the Google App Engine Datastore. Old: class Logo(db.Model): name = db.StringProperty() image = db.BlobProperty() New: class Logo(db.Model): name = db.StringProperty() image = db.BlobProperty() is_approved = db.BooleanProperty(default=False) How to query for the Logo records, wh...

Run db query (sql server 2005) with ajax. Is it possible?

I never worked with ajax. I need to know if it is possible to use ajax to run a query on the db (sql server 2005). My target is to run a query with refreshing the page. Have you got any ideas? ...

How to browse results with php mssql ?

I'm working with php and I want to do a next button that's step to the next 10 records (like when you browse question with stackoverflow) I don't know how to do that but I'm thinking to do it with Top n record ? Do you think that's a good idea ? Any suggestion? ...

Joining on varchar(50) foreign key slows query

I have this query which is pretty long, but adding a where clause to it, or joining on a string makes it take an extra 2 seconds to run. I can't figure out why. Here's the query in full: ALTER PROCEDURE [dbo].[RespondersByPracticeID] @practiceID int = null, @activeOnly bit = 1 AS BEGIN SET NOCOUNT ON; select isnul...

Select from MySQL records that sums

Hello. I know there are a few post out here about selecting records until a certain number is met from the sum of one field but there isn't any that suits me. I'm using PHP and MySQL. I have a table named quantity. Inside there are records of product name, product price and product quantity. Besides these, there are a few others that he...

concat selected values in a single result row, can it be done (without grouping)?

I have the following structure: main: id | meta_data sub: main_id | another_table_id main is connected to sub in a one to many. I wish to get back my result as one record which will look like: [main_id] [meta_data] [another_table_id,another_table_id,another_table_id] Is it possible in MySql without using GROUP BY? ...

Converting SQL containing top, count, group and order to LINQ (2 Entities)

Some LINQ queries still puzzle me. for a table 'Hits' containing two columns, 'Page' and 'Date', I want to find the most Pages with the most rows in a defined slice of time. In SQL I would use this: SELECT TOP 10 [Page] ,COUNT([Page]) as Number FROM dbo.[Hits] WHERE [Date] >= CONVERT(datetime,'14 Jan 2009') AND [Date] < CO...

getting nested results from linq to sql

my data looks like this in the table: ID Name Parent ID --- ---- --------- 1 Mike null 2 Steve 1 3 George null 4 Jim 1 I can't figure out how to write a linq to sql query that will return the results with the parent rows grouped with their child rows. So for example this is the result I...

Query against 250k rows taking 53 seconds

The box this query is running on is a dedicated server running in a datacenter. AMD Opteron 1354 Quad-Core 2.20GHz 2GB of RAM Windows Server 2008 x64 (Yes I know I only have 2GB of RAM, I'm upgrading to 8GB when the project goes live). So I went through and created 250,000 dummy rows in a table to really stress test some queries that L...

Propel - SQL: extract a month from a date

I'm trying to build a query with propel Criteria to get all Foo's in a given month. For example I want all Foo's in March. In regular SQL I would build a query like this: SELECT * FROM FooPeer WHERE MONTH(startDate) = 3 Any Idea how I can implement the "MySQL Month-function within a Criteria Object" ? $c = new Criteria(); $c -> add(...

Count rows added today, yesterday...and other times

I was given good direction to solve a problem today from here but I got stuck in trying to follow this direction. I would like to retrieve a count for all rows from a table for the past 30 days using my date field. I populate these fields using "now()" and they are in the format "2009-03-04 14:58:01". I need a count for the rows added...

How do I run an HqlBasedQuery that returns an unmapped list of objects using nHibernate?

I want to run a query against two tables (which happen to be mapped in ActiveRecord). The query returns a result list that cannot be mapped to an ActiveRecord object (as it is custom aggregate information). For instance Dim query_str as string = "Select distinct d.ID, (select count(1) as exp from Sales_Leads where date_created <= :tod...

How to make a big query on an ASP.NET page for an Oracle DB

I have an Oracle DB, and an ASP Page that has many ListBoxes and DropDownLists. These controls make the user input data to get filtered results on the next page. Once the user clicks search, a string (query) is generated based on the selections of the user. The results page has a datagrid that takes this string and uses it to get data f...

Query duration estimation in SQL Server

I've seen in Oracle 10g a feature that estimates the remaining time for a long running query and I was wondering if this is possible too in SQL Server (at least in 2008?)? Suppose I have a very large table with tens of millions of rows (well indexed etc. etc.) and I need to search for some particular rows. I know it will take a lot of t...

SQL like statement problems

I am having problems executing a prepared statement via mysqli. First I was getting Command out of sync errors. I am storing the result and closing the connection, and I have stopped getting this error, so hopefully the problem has stopped. However, the error in my sql syntax error, which was working fine while the commands were not in...

A query to summarize data in sub-tree?

My data fits a tree form naturally. Therefore, I have a simple SQL table to store the data: {id, parentid, data1, ..., dataN} I want to be able to "zoom in" on the data and produce a report which summarizes the data found below the current branch. That is, when standing in the root, I want to have the totals of all the data. When I ha...

SQL Query to find holes between min_numbers and max_number in a table

Quick question for the SQL gurus. I have a table which contains, amongst others, two columns - min_number and max_number I have been trying unsuccessfully to write a query which finds the first hole of n size between the min and max numbers Example min max 1. 100 200 2. 250 300 3. 330 400 If I want to find a h...