select

MS SQL Server 2000 - check for existing database error

I use MS SQL Server 2000 SP4 and I have this part of script, that checks for existing database: IF EXISTS (SELECT * FROM sysdatabases WHERE name='MY_DBNAME') BEGIN PRINT 'Using the existing database MY_DBNAME.' USE MY_DBNAME END ELSE BEGIN PRINT 'Creating new database MY_DBNAME.' CREATE DATABASE MY_DBNAME END GO I keep...

Why would SqlServer select statement select rows which match and rows which match and have trailing spaces

I have a table created with: SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[TestFeature1]( [Id] [nvarchar](50) NOT NULL, [Leng] [decimal](18, 0) NOT NULL ) ON [PRIMARY] GO SET ANSI_PADDING OFF I inserted data with this: insert into TestFeature1 (id,leng) values ('1',100); insert into Test...

PHP & Postgres: View vs. SELECT, when to use a view?

Related to my previous question: PHP and Databases: Views, Functions and Stored Procedures performance Just to make a more specific question regarding large SELECT queries. When would it be more convenient to use a View instead of writing the SELECT query in the code and calling it: $connector->query($sql)->fetchAll(); What are the ...

SQL standard select current records from an audit log question

My memory is failing me. I have a simple audit log table based on a trigger: ID            int (identity, PK) CustomerID    int                Name          varchar(255)       Address       varchar(255)       AuditDateTime datetime           AuditCode     char(1)            It has data like this: ID CustomerID Name      Address         ...

Is it possible to substitute a value for null in a sql server select statement?

I am moving data from one table to another and I want a date field to change from null to a default value. What is the best way to do this in SQL Server(2000) ? I want something similar to the IIf function in Access. Like IIF(DateBegin is null, #1/1/2000#,DateBegin) ...

Sybase select variable logic

Ok, I have a question relating to an issue I've previously had. I know how to fix it, but we are having problems trying to reproduce the error. We have a series of procedures that create records based on other records. The records are linked to the primary record by way of a link_id. In a procedure that grabs this link_id, the query is ...

jQuery dynamic creation of input fields based on the number selected in a dropdown menu?

I am trying to accomplish something along the lines of this: http://devblog.jasonhuck.com/assets/infiniteformrows.html But... I want to display a dropdown select field, with values 1 to 20, and depending on which value gets selected in that field that's how many input fields I will display to a user to fill out on the page (without ref...

Select with Indented as well as formatted Items in PHP

I have a need to show a select box which will display all categories and subcategories in one go. I want to show All Categories left most & bold while all sub categories will come under respective Categories but will be indented and Italized. How can we create such a Select List in PHP? I have something like this in Magento Ecommerce ...

Possible to substitute ORDER BY w/ other value if 1st value is empty

Is it possible to replace value field_id_36 with field_id_39 if field_id_36 is empty? SELECT wt.title, wt.url_title, wt.weblog_id, wt.entry_id, wd.field_id_36 FROM exp_weblog_titles wt LEFT JOIN exp_weblog_data wd ON wt.entry_id = wd.entry_id WHERE wt.weblog_id = {weblog_id_insert} ORDER BY field_id_36+0 So in theo...

Zend Select with self join overwriting fields

Posts and comments are stored in the same table. So to get each post and its comments we do this: $posts = $this->select()->setIntegrityCheck(false) ->from(array('post' => 'Posts'), array('*')) ->where('post.idGroup = ' . $idGroup) ->where('post.idTopic IS NULL') ->order('post.date DESC') ->limit($resultsP...

Using MySQLdump for sub-set of database migration

I've been using both mysql and mysqldump to teach myself how to get data out of one database, but I consider myself a moderate MySQL newbie, just for the record. What I'd like to do is get a sub-set of one database into a brand new database on a different server, so I need to create both the db/table creation sql as well as populating...

switch statement and loops using jquery/javascript

Is there a way I can generate switch statements in jquery/javascript by using some sort of loop to do the work for me? For example, if I had a statement like: switch ($("#play option:selected").text()) { case '1': $("#play_1").slideDown().find("input").addClass("someClass"); break; case '2': $("#play_1"...

Passing hidden input fields in HTML Select option

Hello, does anyone know if it's possible to pass HTML vlaues in with a form page? So for example if the user selected foo from a list of say 10 options, I would want to pass a hidden value in and retrieve that as a request parameter, e.g. so I could then retrieve the values "foo" and "bar" from the request. Thanks Andrew ...

Magento: Select the top ordered products

I need a block where i can display my "top sellers" but don't know how i can do the collection select. What "addAttributeToSelect" do i need? ...

JQuery: Turn array input values into a string optimization

Hi all, using jQuery I have the following code: var selectedIdsArray = $("#selectId option:selected").map(function(){return this.value;}); var selectedIdsStr = $.map(selectedIdsArray, function(val){ return "" + val + "";}); It successfully retrieves a string of ids eg. selectedIdsStr = "2,45,245,1" from an <select multiple='multiple'>...

MySQL View check if data is NULL

I need to put a Case in the Select to check if the Data I'm adding to my view is NULL, in which case I want it to just enter a zero, or not. ...

Aggregate function with Date on Postgres

I'm kind of rusty on my SQL, maybe you can help me out on this query. I have these two tables for a tickets system (I'm omitting some fields): table tickets id - bigint subject - text user_id - bigint closed - boolean first_message - bigint (foreign key, for next table's id) last_message - bigint (same as before) table ticket_me...

MySQL Select Statement - GROUP BY/Unique

Hello, I'm currently using PHP/MySQL to select some data from my database. My current SELECT statement is: mysql_query("SELECT * FROM tblpm WHERE receiver_id ='$usrID' GROUP BY thread_id ORDER BY unique_id DESC") or die(mysql_error()); There are some columns that have the same "thread-id", thus, I am using the GROUP BY, so that only...

MySQL Select Statement DISTINCT for Multiple Columns

Hi, I am currently trying to construct a somewhat tricky MySQL Select Statement. Here is what I am trying to accomplish: I have a table like this: data_table uniqueID stringID subject 1 144 "My Subject" 2 144 "My Subject - New" 3 144 "My Subject - Newest" 4 211 "Some other colu...

Select Top Viewed From Last 7 Days

I have a table with a date stamp E.g (1241037505). There's also a column with the number of views. The data stamp resembles when it was created. So I want to select the top viewed threads from the past week. How do I do this? ...