sql

SQL search for date between values or Min/Max if NULL

Hi, I have a T-SQL stored procedure where I want to search for a particular value and optionally limit the search to particular dates if they are passed in. If null values are passed in for either of these dates, then I want to ignore those. The way I am thinking of doing this by setting the input dates to minimum or maximum if they are...

how to include the column name in case statement

Hi, I need to include a column name in the where clause of SQL query depending on a variable value. For Example, 1. If I have a variable,say,@test and I assigned the variable with the value 1/0. 2. I have a table ,say, table1 with 2 column names col1,col2. Now, I am writing a query to fetch some data from the table by including only one...

what might be the query to fetch all the records seperated by comma in SQL ?

In SQL, suppose i have a table employee and have a column as Name containing all the names in the format FirstName,LastName. Ex:Nayeem,Khan . I want to fetch all the last names only ie Khan. ...

Problem with chinese characters, php and MySQL

Hallo all, I have a MySQL database with the following settings: MySQL charset: UTF-8 Unicode (utf8) MySQL connection collation: utf8_unicode_ci i have a table with a column named "softtitle", this column is coded in utf8_general_ci. The entries of this column contain chinese characters. If i run SQL through the phpMyAdmin Control pane, ...

Need example how to build SQL database in C#

Need example how to create new local database and a connection string, if possible with a using statement. There should be 1 table and the data that I want to put in there are unique words length 2-50 lowercase characters, and thy can contain "a-zõäöüšž", ordered by ascending. There are 2 actions I want to do with that: Put HashSet o...

Mysql Complex Where Clause

I really surprised when I tried below code in MySQL: SELECT * FROM table WHERE (key='free_shipping' and value='yes') AND (key='price' and value='5') It doesn't work. I need to get product that is both free_shipping is 'yes' AND price equal '5' at the same time. How can I create this query properly? Table Structure: contents: (TABLE...

Trying to optimise a simple SQL update statement with a subquery.

This query is very slow, taking about 1 second per record. Sadly, for (and because of) the size of the database, this is untenable as it will take days to complete. Can you suggest a way to speed it up substantially? (I only need to run it once, but in a <1hr window ideally) update participants set start_time = (select min(time_stamp) ...

"disable" some MySql records so they are not returned when searching?

I have a mysql database which I support using phpMyAdmin. The website this is for is a classifieds website. The issue here is that whenever a new classified is posted (and inserted into mysql database), I need to first review it manually. My question is, is there anyway to tell mysql that "this record is inactive, so don't return it"?...

Delete data from dependent tables

Is there a query in SQL Server 2008 which will delete data from all dependent tables as well, along with the selected table? My apologies for not having elaborated on the question. I know that Cascade Delete would work fine, but my application connects to a 3rd party SQL Server db. I have a few Unit Tests which insert into the target ta...

How to send table to function as argument?

How to send a table to function as argument? Need something like that: CREATE OR REPLACE FUNCTION test(argTable TABLE( field1 integer, field1 integer, etc smallint )) RETURNS integer AS $BODY$ ... Is it possible btw? UPD: I'm going to send a temp table to function so I suppose I need table structure decla...

A few Stored Procedures on sql server values are interchanged

Hi My service is deployed on a few IIS and they execute a considerable number of instances (100-200) of 3-4 different Stored procedures simultaneously. The SPs are executed Via "executescalar". All SPs are returning different value types. I realized that the values have been replaced for SP calls that are made at same time. I am sure a...

Is Android's SQLiteStatement (prepared statement) thread-safe? I.e. is "bind*, bind*... execute" atomic?

I'm wondering whether prepared statements in Android (instances of SQLiteStatement) are thread-safe. In particular I'm asking with regard to the following scenario: In a ContentProvider you create a pre-compiled insert statement during onCreate. Then, in the overriden insert method you make use of this statement by binding a set of para...

How to get records for the most recent complete 13 weeks?

I have a MySQL database table, with a unix timestamp field. I am wondering how to get the most recent complete 13 weeks? Update But I need to opt out the current week. So I need the last complete(that ended in past or today) 13 weeks. ...

oracle sql select script help

Can any one please help with select script? desired outcome TABLENAME, ATTRIBUTE, NULLABLE, DATATYPE, LENGTH, DESC, HELP_TEXT having count(datadic.ATTRIBUTE)>1 (because these can only be unique) and is not unique to any other attribute (not include DDKEY and SerNo) with the same value. i.e TABLE2 ADDR4 NULL VARCHAR2 15 Unit ...

SQL Server 2005, Calculating upcoming birthdays from date of birth

This one has bugged me for a while now. Recently when revisiting some code I wrote for a customer a few years ago I was wondering if there is a more elegant solution to the problem. The customer stores all of their clients information including date of birth (date time field) They run an extract every Monday that retrieves any customer...

Boolean vs tinyint(1) for boolean values in MySQL

Hi All, What column type is best to use in a MySQL database for boolean values? I use boolean but my colleague uses tinyint(1). ...

How can you stop NHibernate (via ActiveRecord) adding this_. to a table name in a formula

I'm using Castle ActiveRecord which uses NHibernate underneath and I've added a property with a formula as follows to one of my entities: [Property(Formula = "CAST((select count(*) from [User] as u where u.Email = FriendEmail) as bit)")] public bool FriendRegistered { get; set; } The problem is that now any query for this entity fails...

Recursive stored functions in MySQL

I'm trying to make a function that recursively builds a path for a specific category CREATE FUNCTION getPath(inId INT) RETURNS TEXT DETERMINISTIC BEGIN DECLARE return_path TEXT; DECLARE return_parent_id INT; SELECT CONCAT('/', name) INTO return_path FROM article_categories WHERE id = inId; SELECT parent_id INTO return_pa...

Standard SQL - CHAR to ASCII

Using standard SQL, SQL-92, how can I convert a character to an ASCII value? In MySQL it's easy using the ascii() function, but SQL-92 doesn't have this. ...

SQL Start date is current day then end date is 1 month ago even if its not from the first to the last of the month

Ok I am trying to write a query that says get the current date and make it the start date. Then I want to go a month back from that current date for the EndDate. Is it possible to do this? Like if it was 9-15-2010 as the start date can I go a month back from that to 8-15-2010 or is this no possible....what would you do for like 9-20-2010...