sql

Self Joins instead of subqueries

Can someone figure out how to get rid of the NOT EXISTS statements in the WHERE clause? SELECT TOP 100 PERCENT Ftm.AcctID AS [Acct Id], Act.AccountNumber AS [Account No.], Act.AccountTypeId, ISNULL(Cnt.FirstName, '')+ ' ' + ISNULL(Cnt.LastName, '') AS [Full Name], Ftm.FinTransTypeCode AS [Trans Type], Ftm.F...

SqlException (0x80131904): Line 28: Incorrect syntax near '('.]

Please someone help me! I have an app running on windows 2003 with sql server 2005. When I try to deploy this some app in other server on windows 2003 with sql server 2000, some pages of the app shows the message bellow: Server Error in '/' Application. Line 1: Incorrect syntax near '('. Description: An unhandled exception occurred dur...

getting all values from three different tables .. JOIN problem?

I'm learning mysql and have been trying to get this working, but an error always comes up no matter how I try it - or it just doesn't show anything from the table. I have 3 tables, all with the same amount of columns and name of columns I want to list all the values in alphabetical order by title Tables: General - Temp - Location Col...

SQL SELECT order by 2 columns and group by

Here're the RS return and the sql issued, SELECT *, (UNIX_TIMESTAMP(end_time) - UNIX_TIMESTAMP(start_time)) AS T FROM games WHERE game_status > 10 ORDER BY status, T; game_id, player_id, start_time, end_time, score, game_status, is_enabled, T 65, 22, '2009-09-11 17:50:35', '2009-09-11 18:03:07', 17, 11, 1, 752 73, 18, '2009-09-11 18...

uniqueidentifier vs identity

I noticed asp_membership uses uniqueidentifier, and to me, it seemed like a waste of space, because I could not think of a particular reason to not replace it with identity. However, SQL Server is not letting me change it to int. It says "Conversion from uniqueidentifier to int is not supported on the connected database server". After...

how to get the updated(not count) row on update the table.

Hello everyone, i want to get the rows that is updated by update command, but the result comes only the no of rows that are updated but i want the whole rows as in select command, so please tell me if anyone have any idea about it. i was trying this. update newTable set readKey='1' where id in (select id from newTable where id='1111') ...

Inserting raw (binary?) image data into mysql? (PHP)

I've got a raw/(binary?) image like this: ÿØÿà�JFIF��–�–�*!!!$'$ &(goes on forever); when i try to insert this into mysql it doesn't work, the column type is set to longblob, any ideas? ...

Query to get all table names

Can any one tell me that how to get names of all tables of a database using asp.net ...

Should these be 3 SQL tables or one?

This is a new question which arose out of this question Due to answers, the nature of the question changed, so I think posting a new one is ok(?). You can see my original DB design below. I have 3 tables, and now I need a query to get all the records for a specific user for running_balances calculations. Transactions are between user...

PHP/MYSQL grab data from of all matching fields

What is the propper syntax to grab data from of all the matching fields? This example outputs only 1 of the matching fields: $myvariable = "SELECT post_content FROM wp_posts WHERE post_name = 'testing' AND post_status = 'publish' AND post_type = 'post'"; echo = $...

MySQL perform several queries with OR

Can someone please help me with how I can add several different queries to one query with OR? I have posts that I only want to show to user that are allowed to see it OR groups that are allowed to see it OR every on. SELECT p.*, c.name, cb.categoryId FROM Posts AS p LEFT JOIN CategoryBindings AS cb ON cb.postId = p.id LEFT JOIN Categor...

CREATE TABLE AS SELECT killing MySQL

We run a MySQL server with moderate load (200-300 QPS) on quite powerful hardware (HP DL360 with 8 Xeon cores, 8Gb RAM and RAID10). All the tables are innodb and the active dataset fits within the allocated innodb_buffer_pool_size. Our database is normalized and to reduce the number of joins we use materialized views to flatten the data...

Convert SQL Server signed int to Binary(4)

I messed up. I wanted to store IP addresses compactly in SQL Server and chose 'int' for the column type. 'int' are 32 bit signed integers while IPs really are 32 bit binarys. My question is: How do I convert my existing signed int into Binary(4) in SQL Server and how should I properly parse the string-IP representation from .Net 'Reques...

SQL - Updating records based on most recent date

I am having difficulty updating records within a database based on the most recent date and am looking for some guidance. By the way, I am new to SQL. As background, I have a windows forms application with SQL Express and am using ADO.NET to interact with the database. The application is designed to enable the user to track employee att...

SQL Server XML Data Type query issue.

Please see below SQL Server 2005 script Declare @xmlData XML SET @xmlData = '<?xml version="1.0"?> <bookstore xmlns="http://myBooks"&gt; <book genre="autobiography" publicationdate="1981" ISBN="1-861003-11-0"> <title>The Autobiography of Benjamin Franklin</title> <author> <first-name>Benjamin</first-name> <l...

Recommended approach on handling SqlExceptions in db applications

Hi, I work on a database application written in C# with sql server as backend. And for data integrity, I try to enforce as much as possible on database level - relations, check constraints, triggers. Due to them, if data is not consistent, the save / update / insert can fail, and app throw SqlException. I do various validations both i...

Suggestions on storing passwords in database

Here's the situation - its a bit different from the other database/password questions on StackOverflow.com I've got two sets of users. One are the "primary" users. The others are the "secondary" users. Every one has a login/password to my site (say mysite.com - that isn't important). Background: Primary users have access to a third sit...

using sql scripts in javascript

can i use javascript to save an item to a database using sql script? ...

PostgreSQL simple trigger question

trigger: CREATE TRIGGER "tr_update_ts" BEFORE INSERT OR UPDATE ON "public"."test" FOR EACH ROW EXECUTE PROCEDURE "public"."update_ts"(); and the function is: CREATE OR REPLACE FUNCTION "public"."update_ts" () RETURNS trigger AS $body$ DECLARE BEGIN NEW.ts := now(); RETURN NEW; END; $body$ LANGUAGE 'plpgsql' VOLATILE CALLED ON ...

MySQL Combining UNION and LIMIT Operations

Hi, I have a JOBS and a COMPANIES table, and I want to extract 20 jobs that meet the following criteria a) jobs only from 2 named companies b) there can at most be 10 jobs per company I have tried the following SELECT with UNION DISTINCT, but the problem is that the LIMIT 0,10 applies to the whole result set, whereas I want it to apply...