sql

MySQL function to get list of Mondays

What is the most efficient way to get a list of all of the unique Mondays from a date field? When I'm not all that concerned about efficiency, I have done something like: DATE-weekday(DATE) + 1. But now I need to compute this on a large dataset and I don't want my user wishing for a Rubik's cube because it is taking so long. :) Yes, ...

frustrating query - news feed like facebook

im trying to have news feed like facebook. Database Dump http://www.2shared.com/document/RXQ13S-n/exported.html i have feed table, which gets feed for text, image or video. i want to group the latest video and images feed and show them as one row and if someone feed comes after it, then group gets break for that row. the following que...

MATCH() AGAINST() & Fulltext index: Possible to have "keywords" field?

Hi, I'm using MATCH() AGAINST() with a fulltext index and I was wondering how I could setup a "keywords" data field. So let's say I have a a fulltext index on the "title" column, which for example might have a row with the value of "AC/DC".. I want to have a field to enter additional keywords like "ACDC" "AC DC" and "AC-DC" Ideally I'd...

TSQL CASE LTRIM (RTRIM NULL

SQL Syntax is still something I am learning. I am getting the error noted below the this snippet of code. SELECT CASE WHEN LTRIM(RTRIM(cLehmanNo)) =' ' THEN NULL WHEN cLehmanNo IS NOT NULL THEN REPLACE ( cLehmanNo,SUBSTRING (cLehmanNo,PATINDEX( '%[^a-zA-Z0-9 '''''']%',cLehmanNo),1), ' ' ) END asLOAN_NUMBER ,CASE WHEN ...

How to store ordered items which often change position in DB

I need to be able to store a large list of ordered items in the DB. So far that's straight-forward: ID Position OtherFields 1 45 ... 2 4736 ... 3 514 ... ... In queries, I always need to get just a few items (filtered based on OtherFields) but in the correct order. Easy as well, putting an index on Position...

nvarchar concatenation problem.

Hi All, I am probably trying to do a simple thing after dealing with all the hard stuff but seems like this is giving me a headache. I am trying to concatenate text into variable @strXml which is an nvarchar variable to build Xml element, but @strXml returns null. Please help. I am posting my code below. DECLARE @strXml nvarchar(max) = ...

MySQl query problems

I don't spend a whole lot of time in MySQL, but I have been asked to look into a problem with my church's website. It has been down for quite some time and I am trying to get it back up and running. The original site was done in Mambo 4.5.3, which is an old version. I will upgrade it at some point, but I just want to get it running fo...

Limit SQL query result in MySQL

I would like to limit the amount of rows I fetch in MySQL. Can you show me how? ex: 1st query I would like to retrieve only the first 10,000 records 2nd query I would like to retrieve only records from 10,000 - 20,000 etc ...

SQL Sort Order by The Order Specified In the Query

Say I have a query "select * from clauses where id in (0,2,5,1,3)" and I actually want the rows returned in the same order they are specified the where clause. The order of the IDs will change from query to query and there is no pattern to the order. I know it's possible to alter the data model, create temp tables, etc. But trust me ...

Select & Insert across multiple databases with MySQL

I have 2 identical tables in 2 different databases that reside on the same server. What would be the best way to copy data from table to another? ...

Sql Server Catalog/DB pointer --

I have a production server and I standardized the names of all the DBs on the server to projectName.whatever The problem is I have one database named projectName_logging I want to rename it to projectName.Logging (OCD a bit?) The problem is there are connection strings that all say projectName_logging. Is there a way to sa...

Why is this SQL SUM statement correct?

In my schema, I have a table Projects, and a table Tasks. Each project is comprised of tasks. Each task has Hours and PercentComplete. Example table: ProjectID TaskID Hours PercentComplete 1 1 100 50 1 2 120 80 I am trying to get the weighted percentage complete for the project...

MySQL Sum based on date range and time of day

Hello, I have a large set of data collected every 15 minutes. I am trying to select data between a certain time period and then within that time period divide it up by another date intervals. And within those intervals sum over a certain time period. For example, I would like to be able to select data between 01/01/2009 and 01/01/2...

Preferred syntax for adding SQL SUMs together

I want to return the total sales. That is to say the UnitPrice + TaxAmount for the entire set of data. I can write the SQL query two different ways with the same result returned. SELECT SUM(UnitPrice + TaxAmount) AS 'TotalSales' FROM Sales or SELECT SUM(UnitPrice) + SUM(TaxAmount) AS 'TotalSales' FROM Sales Is one of these que...

accessing a bind variable in sqlplus

In the following example, variable recordId number; BEGIN SELECT MAX(recordvalue) INTO recordId FROM sometable; END; PRINT recordid; SELECT * FROM someothertable WHERE recordkey = &recordId; The select statement on the last line cannot access the value of recordId. I know i can access recordId inside the pl/sql bl...

Declaring & Setting Variables in a Select Statement

I'm attempting to write a simple query where I declare some variables and then use them in a select statement in Oracle. I've been able to do this before in SQL Server with the following: DECLARE @date1 DATETIME SET @date1 = '03-AUG-2010' SELECT U.VisualID FROM Usage u WITH(NOLOCK) WHERE U.UseTime > @Date1 From the searching I've ...

Select rows whose IDs are not found in another table under certain constraints

The practical problem I'm solving is to display a list of items that have been updated recently that the user has not viewed recently. I'm trying to return a table containing items that are not containing in an item views table for a given user (let's say for this case user number 1). I've come up with: SELECT * FROM items i WHERE i.up...

MySQL: Possible to have wildcards in AS aliases?

I have a bunch of fields named the same across multiple tables (I inherited it - don't blame me ;). Instead of setting up all of the aliases verbosely, is it possible to assign/prepend an alias automatically by way of a wildcard? I'm envisioning something like (which of course doesn't really work): SELECT t1.*,t2.* as alias2.*, t3.* ...

Populating PictureBoxes with webimages via SQL fields.

I have a potential of up to 4 images per database row/entry and I am querying on Gridview_currentRowChanged. The issue was how to clear the picturebox(s) before loading the next row. private void radGridView1_CurrentRowChanged(object sender, Telerik.WinControls.UI.CurrentRowChangedEventArgs e) { panelImages.Contro...

how to declare global variable in sql

Hi, I would like create a GLOBAL VARIABLE in a Sql script. For my understanding using DECLARE I will be able to create just LOCAL variable. Any idea how to create theem? thanks ...