sql

I am trying to get comfortable creating joins with T-sql 2008

I am trying to write this select statement. My select statement consists of a join that returns all of the first and last names of my fictional employees, their department names and I am trying to group the individuals by their respective departments. This is the code I wrote: select e.First_Name,e.Last_Name,Department_Name from EMPL...

SQL problem with 12 subquery

Exists such db schema: I need to write query. For every doctor i need average cost of visit by month for 2009 year. The result is (name_of_doctor, january, febriary, ..., december) I know how to do this with 12 subquery. Exists another more convinient way? ...

ABAP: How to combine select max and count?

Hello, I've got this: select ordernr from users having count(ordernr) = ( select max(count(ordernr)) from users where ordernr = ordernr group by ordernr ) group by ordernr to get the most used order-number (ordernr) from all users. How to get it into ABAP SAP System? I've tried this: select SINGLE ordernr from ZDEVXXX...

What are the best PHP input sanitizing functions?

I am very new to PHP/programming, with that in mind I am trying to come up with a function that I can pass all my strings through to sanatize. So that the string that comes out of it will be safe for database insertion. But there are so many filtering functions out there I am not sure which ones I should use/need. Please help me fill in ...

What should I use for the backend of a 'social' website?

My two main requirements for the site are related to degrees of separation and graph matching (given two graphs, return some kind of similarity score). My first thought was to use MySql to do it, which would probably work out okay for storing how I want to manage 'friends' (similar to Twitter), but I'm thinking if I want to show users r...

Please help with correcting some quick SQL syntax, inner join on new column.

Ok so say I Col1,Col2, and COl3 exist in MyTable. However, [Interval] does not. Select Col1,Col2,Col3, [Interval] = CASE WHEN (cast(segstart as float) - floor(cast(segstart as float))) >= (cast(@TweleveAM as float) - floor(cast(@TweleveAM as float))) THEN CAST('0' as smallint) End FROM MyTable But now I want to use the new column I m...

Starting MySQL Error on Snow Leopard

I just erased and re-installed Snow Leopard. I installed MySQL 5.1.48 64-bit clean. I'm having issues with the MySQL server... when I boot the computer and log in, the server is not running. I tried to start it using the preference pane by clicking "Start MySQL Server", but all it did was highlight the button blue and think for like a mi...

updating a sum of one table based on input from another table

Hello, We've the following SQL that we use to calculate total costs. SELECT DailyProduction.CustomerId as CustomerId, SUM(Resource.CostPerUnit * DailyProduction.UnitsToStorage + Resource.CostPerUnit * DailyProduction.UnitsToMarket) AS TotalCost FROM dbo.hgm_ResourceTypes Resource JOIN dbo.hgm_ResourceDailyProduc...

Error connecting to SQL from WCF Using LINQ - but affects only one server

That's a horrible title, sorry. Here's the scenario: WCF Service uses LINQ to get data from a SQL database. Service is deployed on 4 (nearly) identical servers running under IIS. All are talking to the same SQL server on a separate machine. 3 of the 4 servers are working great. On the 4th server we're getting this A network-rel...

How do I optimize MySQL queries?

I'm currently using mysql w/ PHP because that's what I learned and haven't ever had to use anything else. In my current project, I have a database w/ 10 million rows and about 10 columns and have found it to be very slow when I do complex calls, both in a local (windows) environment as well as production (linux) environment. Both servers...

Creating SQL View, replaceing variables with actual variables doesn't work for me

First, let me thank you for helping! Now I'm converting a query to a view in SQL so I need to replace all my variables with actual values. However I am running into trouble when doing this. When I have DECLARE @TweleveAM datetime set @TweleveAM = '1900-01-01 00:00:00' DECLARE @TweleveThirtyAM datetime set @TweleveThirt...

The correct syntax for a T-SQL subquery and a possible join

What would be the correct syntax and join (if any) of a subquery that would return all of the employees first and last name from the employee’s table, and return their department name from the department table, but only those employees who more than the average salary for their department? Thanks for your answers ...

Query to get records based on Radius in SQLite?

I have this query which does work fine in MySQL SELECT ((ACOS(SIN(12.345 * PI() / 180) * SIN(lat * PI() / 180) + COS(12.345 * PI() / 180) * COS(lat * PI() / 180) * COS((67.89 - lon) * PI() / 180)) * 180 / PI()) * 60 * 1.1515 * 1.609344) AS distance, poi.* FROM poi WHERE lang='eng' HAVING distance<='30' distance is...

Advice on deploying CRUD WPF clients for fairly small applications

Let's say I want to create an application, fairly simple CRUD with 3-5 tables. Imagine a Todo list application for example. What is the best way to approach the data layer in WPF for this to be a click-once application. I'd rather not do it in the cloud (although if I can add an easy backup process in the background, that's a big plus)....

function to generate names for non registerd users

How to create or what is the logic of function which Generate names for non registered users using given name as string variable using sql 2005 (like registering in hotmail ,yahoo) ...

Date difference in SQL Server 2005.

Hi, Let's say I have two dates in my table, DueDate and PaidDate. What I need to do is calculate the difference between those two dates. However, if the DateDiff() returns less than 0, it should show 0. DateDiff(Day, 0, (PaidDate-DueDate-1)) as DelayDays Should show 0 for anything less than 1. Thank you. ...

How to select all rows with a unique field, and get all fields in that row in the result set in MySQL?

I have a table say something like this: column_a column_b foo 1 bar 1 baz 2 I need to get this in my result set: foo 1 baz 2 Thus, I need to select rows where the field column_b is distinct. I tried coming up with ways to do this by using a subquery with select distinct but no dice. I'm still ...

Run multiple commans or sql script using OLE DB in SQL Server

It is possible to run multiple commands or sql script using OLE DB? For example to run sql script to create database and its structure (tables, indexes, stored procedures...). When I use CCommand class, I can run only one command. How can I run SQL script with multiple commands? Thanks, Martin ...

Sql select null and non null values in WHERE clause

I am trying to run a query that selects values from a table using a WHERE clause , the query only returns the rows where all of the conditions have values, hoe do I go about returning the values that are also null? Language Table Students Table ID Language ID Student L...

How to fetch records in pages in Android

I want to use the SQLite clause LIMIT and OFFSET, so that I can fetch my records in pages. But, though I can find the LIMIT clause in the SQLiteQueryBuilder.query() which would effectively limit the number of record in my result. Couldn't find the OFFSET clause anywhere so that I can continue fetching from the point I left. Also, can so...