sql

What are differences between INSERT and UPDATE in MySQL?

It seems INSERT and UPDATE do the same things to me. Is there any occasions where I should use INSERT instead of UPDATE and vice versa? ...

Decimal number with comma instead of point (php and sql)

Hi, I'm doing a little application of adding prices and decimals. Points are normal to use with decimals, but how can I write decimal number with comma as input (543,35 instead of 543.35) and then maybe change it with point to the database (mysql)? Then print it back form the database with the comma. Reason is that comma (,) is more use...

How to query Microsoft Access Database fields from VBA in Excel

Hey guys, I am currently writing a program to save stuff entered in a form in Excel into a database in Access. I am trying to increment a primary key field within Access by "1" whenever I add data from the fields in my Excel form. Because I have declared this field as a PRIMARY KEY NOT NULL field, it doesn't allow me add another row o...

MySQL - Conditional Foreign Key Constraints

Hi there, I have following 'comments' table in my app: comments -------- id INT foreign_id INT model TEXT comment_text TEXT ... the idea of this table is to store comments for various parts of my app - it can store comments for blog post i.e: 1|34|blogpost|lorem ipsum... user picture: 2|12|picture|lorem ipsum.....

How to make a drop down list (list box)in an MS Acess Query with values from two different tables.

I need the drop down box above to display the date as shown and the ClassTypeDesc as you can see above the dropdown list shows 1/12/2010 twice. They have different ClassTypes Assigned to them. The drop down list should show: 1/12/2010 ACLS-I Day One AM 1/12/2010 ACLS-I Day One PM I need to know the statement to put in the Row Sour...

SELECT id_field WHERE max(date_field) < 'some date'

I'm sure this question is obvious, but I've been fiddling with an increasingly complex set of subqueries for the last hour or so and getting nowhere. I need to select a bunch of ID's from a table where the last date for that record is before a given date. I was trying: SELECT id_field WHERE max(date_field) < 'some date' But getting '...

autosizing sql server database diagram view

i see there is "arrange tables" that organizes your table relationships to be clear. is there anyway to autosize the tables so it shows: the full name of the table the full height to show all fields. i find myself tweaking tables over and over manually and its a pain. I would hope there would be some way to auto correct the sizing ...

How can I escape single and double quotes in SQL prepared statement?

I have a SQL statement similar to the one shown below in Perl: my $sql="abc..TableName '$a','$b' "; The $a is free text which can contain anything including single quotes, double quotes, back- and front-slash characters, etc. How can these characters be escaped to make the SQL statement work? Thanks. ...

Converting BlobColumn to String in SSIS Script Component.

Hello.. How to convert BlobColumn to String in SSIS Script Component. Ex: Source Column : OrganisationProviderID NVARCHAR(MAX) Destination Column : OrganisationProviderID VARCHAR(20) How can this be acheived in SSIS Script Component Thanks ...

Translating INTERSECT statement to MySQL

I have the following query using INTERSECT and I can't figure out how to translate it to MySQL using INNER JOIN. SELECT DISTINCT Title, Variable FROM Table WHERE Location='Location1' AND Date='Date1' INTERSECT SELECT DISTINCT Title, Variable FROM Table WHERE Location='Location2' AND Date='Date2' INTERSECT SELECT DISTINCT Title, ...

Counter variable in SQLite

I'm working on a simple todo app that has a column for each day of the week. On startup, the app checks to see if there are any incomplete tasks from before the current date. If so, they're moved to the top of the current date's column. The app is cloud-based, but the tasks are backed up for offline mode with an SQLite db. I can easily ...

When should I create database indexes?

Hai guys, when to set index for a table (ie) during table creation or on performance tuning? What are the advantages and disadvantages of indexing? ...

SQL CASE [Column] WHEN IN ('case1', 'case2') THEN 'oops' END?

Is there a way to check a CASE when it's in an array: SELECT CASE [Option] WHEN IN (1, 3, 99) THEN 'Wrong option' ELSE 'You go!' END ...

Removing duplicates in SQL Server - Unusual Scenario

Hi Guys, The database I'm currently working on is for a scientific instrument that records data at certain points in time. My instrument records per second, but with a resolution of 5 seconds. ID Total Particles DateandTime 38313 602 2009-01-27 16:25:48.000 38314 602 2009-01-27 16:25:49.000 38315 ...

SQL Query: Which one should i use? count("columnname"), count(1)

Hi , I don't know whether this is correct forum for sql query, but i have stucked that's why asked question. Highly sorry for that. In my sql query, i just need to check whether dataexist for perticular userid. Here always, only one row will return when data exist. I have two options 1. select count(columnname) from table where use...

approaches to encrypt password in sql server 2005

Hai guys, Thus far i am using the following statements for encrypting a password variable in sql server 2005 OPEN SYMMETRIC KEY SecureSymmetricKey1 DECRYPTION BY PASSWORD = N'StrongPassword'; DECLARE @encrypted_str VARBINARY(MAX) select @encrypted_str=EncryptByKey(Key_GUID('SecureSymmetricKey1'),@Password) Is this a good practice o...

Best way to write this query.

I have two MySql tables as shown below with the data shown: CREATE TABLE `A` ( `id` int(12) NOT NULL AUTO_INCREMENT, `status` varchar(50) DEFAULT NULL, `another_field` varchar(50) DEFAULT NULL ) INSERT INTO `A` VALUES ('1', null, 'a'); INSERT INTO `A` VALUES ('2', null, 'b'); INSERT INTO `A` VALUES ('3', null, 'c'); CREATE TABLE `B`...

Split XML tags and transform to SQL

I want to transform a large xml file to sql statements with xslt. For example I have the author tag. <author>Evans, Jim; Henderson, Mike; Coyier, Alan</author> I have a column for last_name and first_name, so Evans, Henderson and Coyier should go to last_name and so on. How can I pick them out of the tag and put it into sql statement...

ASP.NET / SQL drop-down list sort order

I am trying to correct the sort order of my ASP.NET drop down list. The problem I have is that I need to select a distinct Serial number and have these numbers organised by DateTime Desc. However I cannot ORDER BY DateTime if using DISTINCT without selecting the DateTime field in my query. However if I select DateTime this selects eve...

How can I execute a SP and depending on it's result execute another query which if fails should revert back what the SP has done?

I think it's a basic SQL question...sorry..new to it... :-) I want to execute a SP inside which { I want to execute a SP (using EXEC) and depending on it's result I want to execute another query (INSERT) which if fails for any reason should revert back what the SP has done? } How can I do this? Transactions? If yes, how? PLEASE...