sql

SQL query based upon some criteria

sir, it like searching at function i need to search the table which has data stored in ms access table. i have create a text box for the contract no,username and date and need to search the table according to contract no or username or date. for that i need a coding with solve the problem in single sql command. i have try it with where...

Connecting to a named instance of SQL Server 2008 from classic ASP

My ASP application connects to the network server where SQL Server 2000 is installed with no problem. The old code that works: myConn.Open ("Driver={SQL Server}; Server=myNetwrkServer; Database=myDB; UID=myID;PWD=myPWD;Trusted_Connection=NO;") An instance of SQL server 2008 was installed on t...

How do I use a correlated sub query for a new column in my view?

Hi, I am trying to write a view that has 3 columns: Planet, Moon, and Largest. The view is meant to show planets, their moons, and a Yes or No column indicating whether or not it is the largest moon for the planet. Only one Basetable is used, and the columns I am referencing are moonPlanetOrbit (only not null if bodyType is = to 'Moon'...

SQL dates to time to minutes minus work days.....confused

The following code has been created from a different post, but I now have a separate issue. What this code does is basically takes the 2 dates and subtracts weekends from it to get the overall time elapsed in minutes from start to end time excluding weekends. I am now trying to say since there is 11 hours in a work day for me I want to o...

Error when inserting into SQL table with php

So this is my code: function function() { $isbn = $_REQUEST["isbn"]; $price = $_REQUEST["price"]; $cond = $_REQUEST["cond"]; $con = mysql_connect("localhost","my_usernam", "password"); if (!$con) die('Could not connect:' . mysql_error()); mysql_select_db("my_database",$con); $sql="INSERT INTO 'Books' (isbn, price, condition) VALUES ('...

SQL 2008 Full Text Search Word Proximity

Hello Folks, I have been reading the Full Text help files for CONTAINS, FREETEXT, CONTAINSTABLE and so forth on MSDN and elsewhere, but I am not able to find the solution I am looking for. I would like to be able to query with the following criteria: Example value: "The quick brown fox jumped over the lazy dogs." Select * from MyText...

Grab Next Row in SQL

I am trying to grab a field from the next row of this database. I can use the logged on time to determine the logout time but I would like to also grab the next login time so I can determine the logout [logged off] time as well. Any suggestions? Thank you |-LogonDate---|-PersonID-|-LoggedOnTime---| |5/30 12:00pm |100 |3600 ...

SQL Only get numbers after decimal

Example 2.938 = 938 Thanks ...

Split concatenated field into separate parts

Using SQL Server 2008, I am trying to do something similar to this post regarding splitting a concatenated field into separate parts for normalization purposes. The problem with the solutions in the linked post is that they only work for delimited values. The data I am attempting to split would be similar to: UserID -- ConcatField 1 -...

Alternative to DISTINCT Function

Is there a better way to get all distinct values from three columns in one table other than using the DISTINCT function? I've also tried GROUP BY, but there doesn't seem to be any noticeable difference in the cost. SELECT DISTINCT Table1.Col1, Table2.Col1, Table1.Col3 FROM Table1 INNER JOIN Table2 ON Table1.FK = Table2.ID WHERE Table1....

Stop execution when ROLLBACK an SQL transaction

Is there a way to stop executing code once I ROLLBACK a transaction in T-SQL? For example, in the code below I want 'Message 1' to print, but not 'Message 2'. BEGIN TRANSACTION GO PRINT 'Message 1' ROLLBACK TRANSACTION GO PRINT 'Message 2' GO ...

Any popular Rails tricks for keeping a nav's css selected when flipping through partials?

I have an admin with a nav. The nav toggles between different partials. The nav has several li's, and when one of them is selected, it gets the .selected class that makes it highlighed. Is there anyway to toggle this from the controller? Or any other place that's popular among Rubyists? ...

MySQL: Get Root Node of Parent-Child Structure

I have a table similar to this: ================= | Id | ParentId | ================= | 1 | 0 | -----+----------- | 2 | 1 | -----+----------- | 3 | 0 | -----+----------- | 4 | 3 | -----+----------- | 5 | 3 | -----+----------- | 6 | 0 | -----+----------- | 7 | 6 | -----+----------- ...

SQL Server query - loop question

I'm trying to create a query that would generate a cross-check table with about 40 custom columns that show Y or N. Right now I have SELECT DISTINCT [Company], [Option1], [Option2], [Option3], CASE WHEN [Table1].[ID1] IN (SELECT ID2 FROM Table2 WHERE Variable = 1 AND Bit = 1) THEN ...

SQL Stored Procedure Issue - Decimal Value Conversion Issue

I am running into a very strange problem in a SQL Server stored procedure. I have two databases. One contains the database for my billing system. The other is a reporting system with summarized data. Within this database there is a table with summarized job information. When this data is created, one of the fields, BilledToDate, i...

SQL need to subtract certain time from date paramter passed into query

I have a date parameter so the date and time can always change. For this example the datetime is '2010-07-06 14:46:37.577' I need to see how much time is between this date paramter and the time of '17:00:00.000' The time of 5PM will never change but as I said the date paramter can change. ...

MySQL Select Unique Pairing of Names

I am having trouble with a mysql query. I want to get a unique pairing of names that share the same tenant_group_id number. All you need to know is that each tenant has a unique individual_tenant_id and up to two individual tenants share the same tenant_group_id. SELECT t1.first_name, t2.first_name FROM individualtenant t1 ...

SQL advanced query - problem with single row aggregate sub query in select clause

I'm trying to execute the following query but I receive a runtime error stating that: "The column is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause." Line number two below is the one that fails with the error above. I don't understand why this query doesn't execute as no g...

python or database?

i am reading a csv file into a list of a list in python. it is around 100mb right now. in a couple of years that file will go to 2-5gigs. i am doing lots of log calculations on the data. the 100mb file is taking the script around 1 minute to do. after the script does a lot of fiddling with the data, it creates URL's that point to google ...

SQLite3 (or general SQL) retrieve nth row of a query result

Hi All, quicky question on SQLite3 (may as well be general SQLite) How can one retrieve the nth row of a query result? row_id (or whichever index) won't work on my case, given that the tables contain a column with a number. Based on some data, the query needs the data unsorted or sorted by asc/desc criteria. But I may need to quickly ...