sql

Putting sql result set into JList

Hi there. I'm working on my second year project and I'm nearly finished, but I've got a problem. I have a table set up in Oracle that holds user names, recipients, and messages. I wanted to make a contacts list for sending messages that would take the user names and put them into a swing jlist but i cant figure out how. I thought m...

Query between SQL server and Client side

I create a query: Select * from HR_Tsalary where month='3' and year ='2010' the result is 473 records and I found 2 duplicate record, then I create another query to find duplicate record only: SELECT Emp_No, COUNT(*) FROM HR_Tsalary WHERE year = '10' AND month = '3'GROUP BY Emp_No HAVING COUNT(*) > 1 the result is zero record from cl...

Visual Studio 2010's SQL Schema & Data Compare - Can it be accesed from code?

The other day I tried out VS2010's SQL compare tools and thought they were awesome. I am wondering if there is any way to harness these tools in code written in VS 2010. ...

DB2 Child Table Not Working - Create Table

I have a bit of a task before me. (DB2 Database) I need to create a table that will be a child table (is that what it is called in SQL?) I need it so that it has a foreign key constraint with my other table, so when the parent table is modified (record deleted) the child table also loses that record. Once I have the table, I also need t...

Sql Server - How to calculate the size of some rows from each table in a database?

How can i calculate the size of only some rows for each table? For example, with the code: EXEC sp_spaceused 'myTable' you obtain the size of all rows, however i want to calculate the size not of one single table, but all of them, and using the same clause for each one, something like this in pseudo-code: foreach(Table myTable in Da...

SQL search for containing terms

Hi, If it possible to search in a table for records of which its name contains a search term? Thanks ...

Design Practice Retrieve Multiple Users - PHP

Greetings all, I'm looking for a more efficient way to grab multiple users without too much code redundancy. I have a Users class, (here's a highly condensed representation) Class Users { function __construct() { ... ... } public static function getNew($id) { // This is all only example code $sql = "SEL...

NHibernate Query across multiple tables

I am using NHibernate, and am trying to figure out how to write a query, that searchs all the names of my entities, and lists the results. As a simple example, I have the following objects; public class Cat { public string name {get; set;} } public class Dog { public string name {get; set;} } public class Owner { public string...

SQL IF ELSE with output params stored proc help

Hi All, I have a stored proc (SS2008) that takes a couple int ids and needs to look up if they exist in a table before adding a record. I have an int output param I would like to return and set its value based on what occrured. I have this so far, but it always returns 1. Can someone point me in the right direction? BEGIN TRY IF EXIS...

what if system crashes when i type SQL command

I have some doubt as follows We are UPDATING a field in SQL and ALTER the row also.After giving the COMMIT command the system is crashed.Wat will happen to the commands given,whether it will UPDATE and ALTER the table r not? ...

MYSQL count all rows per table for in one query

Is there a way to query the DB to find out how many rows there are in all the tables ie table1 1234 table2 222 table3 7888 Hope you can advise ...

Most concise way to convert Julian date (yyyy[day of year]) to SQL datetime

I'm working with an existing database where all dates are stored as integers in the following format: yyyy[3 digit day of year]. For example: 2010-01-01 == 2010001 2010-12-31 == 2010365 I'm using the following SQL to convert to a datetime: DATEADD(d, CAST(SUBSTRING( CAST(NEW_BIZ_OBS_DATE AS VARCHAR), 5, LEN(NEW_BIZ...

Dynamic SQL Rows & Columns...cells require subsequent query. Best approach?

I have the following tables below City --------- CityID StateID Name Description Reports --------- ReportID HeaderID FooterID Description I’m trying to generate a grid for use in a .Net control (Gridview, Listview…separate issue about which will be the ‘best’ one to use for my purposes) which will assign the reports as the columns an...

MySQL -- How to do this better?

$activeQuery = mysql_query("SELECT count(`status`) AS `active` FROM `assignments` WHERE `user` = $user_id AND `status` = 0"); $active = mysql_fetch_assoc($activeQuery); $failedQuery = mysql_query("SELECT count(`status`) AS `failed` FROM `assignments` WHERE `user` = $user_id AND `status` = 1"); $failed = mysql_fetch_assoc($failedQuery); ...

SQL Query Math Gymnastics

I have two tables of concern here: users and race_weeks. User has many race_weeks, and race_week belongs to User. Therefore, user_id is a fk in the race_weeks table. I need to perform some challenging math on fields in the race_weeks table in order to return users with the most all-time points. Here are the fields that we need to m...

MySQL select using datetime, group by date only

Is is possible to select a datetime field from a MySQL table and group by the date only? I'm trying to output a list of events that happen at multiple times, grouped by the date it happened on. My table/data looks like this: (the timestamp is a datetime field) 1. 2010-03-21 18:00:00 Event1 2. 2010-03-21 18:30:00 Event2 3. 2010-03-30...

How to optimise MySQL query containing a subquery?

I have two tables, House and Person. For any row in House, there can be 0, 1 or many corresponding rows in Person. But, of those people, a maximum of one will have a status of "ACTIVE", the others will all have a status of "CANCELLED". e.g. SELECT * FROM House LEFT JOIN Person ON House.ID = Person.HouseID House.ID | Person.ID | Person...

Finding gaps (missing records) in database records using SQL

I have a table with records for every consecutive hour. Each hour has some value. I want a T-SQL query to retrieve the missing records (missing hours, the gaps). So for the DDL below, I should get a record for missing hour 04/01/2010 02:00 AM (assuming date range is between the first and last record). Using SQL Server 2005. Prefer a set ...

SQL Date rows for inactivity days

Hello. Let's say there is this table which stores the number of visitors for each day. When I want to query the table and create a graph from it a problem arises. The days without activity have no corresponding rows on the table. For example Day1 - 7 Day2 - 8 Day4 - 7 And the graph generated would not be correct. Since it needs a ...

Is it possible to submit data into a SQL database, wait for that to finish, and then return the ID generated from SQL, using Classic ASP?

I have an ASP form that needs to submit data to two different systems. First the data needs to go into an MS SQL database, which will get an ID. I then need to submit all that form data to an external system, along with that ID. Pretty much everything in the code works just fine, the data goes into the database, and the data will go to...