sql

T-SQL String Replace

Hello All, here goes my first question: I need to replace the tag {URL}: DECLARE @PageUrl varchar(200) DECLARE @Body varchar(MAX) SET @PageUrl = 'http://www.website.com/site1/site2/pageName.asxp?rid=1232' SET @Body = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed luctus, {URL} enim nec posuere volutpat, neque dui volut...

Reset SQL variable inside SELECT statement

I am trying to number some rows on a bridge table with a single UPDATE/SELECT statement using a counter variable @row. For example: UPDATE teamrank JOIN (SELECT @row := @row + 1 AS position, name FROM members) USING(teamID, memberID) SET rank = position Is something like this possible or do I need to create a cursor? If it hel...

SQL query to identify seasonal sales items

I need a SQL query that will identify seasonal sales items. My table has the following structure - ProdId WeekEnd Sales 234 23/04/09 543.23 234 30/04/09 12.43 432 23/04/09 0.00 etc I need a SQL query that will return all ProdId's that have 26 weeks consecutive 0 sales. I am running SQL server 2...

suggest a method for updating data in many tables with random data?

I've got about 25 tables that I'd like to update with random data that's picked from a subset of data. I'd like the data to be picked at random but meaningful -- like changing all the first names in a database to new first names at random. So I don't want random garbage in the fields, I'd like to pull from a temp table that's populated a...

How to set XACT_ABORT within ADO.NET

How can I set XACT_ABORT to ON (or OFF) from within ADO.NET ? ...

What does null extended mean in relational queries?

I'm reading a paper on SCOPE that discusses SQL like query semantics for big data applications. It does not follow how SQL deals with null values and discusses "null-extended" variables, which I have not encountered before. Consider the pseudo-query SELECT * FROM DATA WHERE A != B What does "the predicate A != B is satisfied only f...

Selecting max of a sum of two columns

I have a table comparisons. If I run SELECT comparisonID,stu1Vers,stu2Vers,stu1,stu2 from comparisons WHERE stu1!=stu2 and assignmentid=9; I get something like: +--------------+----------+----------+------+------+ | comparisonID | stu1Vers | stu2Vers | stu1 | stu2 | +--------------+----------+----------+------+------+ | ...

Can you write a custom aggregation function in SQL? Can you query the contents of a grouping?

I'm trying to convert a Linq query to SQL. My Linq query looks like this: from s in Somethings where s.CreatedTime >= new DateTime(2010, 01, 01) where s.CreatedTime < new DateTime(2010, 02, 01) group s by s.Data into grouping select grouping.OrderByDescending(s => s.CreatedTime) .ThenByDescending( s => s.UpdatedTime) ...

Simple, fast SQL queries for flat files.

Does anyone know of any tools to provide simple, fast queries of flat files using a SQL-like declarative query language? I'd rather not pay the overhead of loading the file into a DB since the input data is typically thrown out almost immediately after the query is run. Consider the data file, "animals.txt": dog 15 cat 20 dog 10 cat 3...

SQL Update to flip sign of a value?

Someone entered a ton of numeric data into a table with the sign backwards. Is there a clean way to flip the sign in the numeric column with a SQL statement? ...

Ruby on Rails Query Help

I currently have the following query User.sum(:experience, :group => "clan", :conditions => ["created_at >= ? and created_at <= ?", "2010-02-15", "2010-02-16"]) I want to return the top 50 clans in terms of experience listed from most experience to least experience with only the top 50 in experience returning. How would I modify the ...

How can I echo a this query?

$result = mysql_query("SELECT car.id car_id, FROM car WHERE car.id= $id "); How can I echo the query above? ...

date comparisons in Rails

Hi there, I'm having trouble with a date comparison in a named scope. I'm trying to determine if an event is current based on its start and end date. Here's the named scope I'm using which kind of works, though not for events that have the same start and end date. named_scope :date_current, :conditions => ["Date(start_date) <= ? AND D...

exclude from union by only one out field ...

SELECT A.ID_ListGroupParIzm, A.Name, 0 AS Point FROM CfgListGroupParIzm A, CfgIzmeritel B WHERE A.ID_TypeIzmerit = B.ID_TypeIzmerit AND B.ID_Izmerit=@ID_Izmerit AND A.ForRun=0 UNION SELECT A.ID_ListGroupParIzm, (C.Name + ' ' + A.Name) AS Name, C.ID_IzmerPoint AS Point FROM CfgListGroupParIzm A, CfgIzmeritel B, CfgIzmerPoint ...

How do I get a count of events each day with SQL?

I have a table that looks like this: Timestamp Event User ================ ===== ===== 1/1/2010 1:00 PM 100 John 1/1/2010 1:00 PM 103 Mark 1/2/2010 2:00 PM 100 John 1/2/2010 2:05 PM 100 Bill 1/2/2010 2:10 PM 103 Frank I want to write a query that shows the events for each day and a count fo...

SQL Server 2005/2008 - Double Click to open table / view first 200 results?

Is there a way to configure the shortcuts etc in SQL Server 2005 / 2008 as per the headline. When I doubleclick on a table, I typically want to open it to view the information within, not to just access the next level on the explorer. When I do this on a procedure, I usually want to modify it. This question is one year overdue as this i...

What's wrong with this SQL Create Table Statement?

This SQL query is generated by SQL Server Managment Studio and it throws me an error: USE [database_name] GO /****** Object: Table [dbo].[UserAddress] Script Date: 02/17/2010 11:21:02 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[UserAddress] ( [ID] [int] IDENTITY(1,1) NOT...

How to manipulate an array similar to an ORDER BY clause in SQL?

My data has been placed into an array, but unfortunately not in the order I want it in... String[][] databaseToArray = { //{"Name", "Channel", "Description", "Amount", "isReady"}, {"John", "Nick", "likes", "2", "yes" }, {"Drew", "MTV", "dislikes", "4", "no" }, {"Fred", "CNN", "okay", ...

Symfony Jobeet: Need to refactor index page DB queries

I use Symfony 1.4 with Doctrine, and I noticed that my project has similar issue with Jobeet project at index page (http://www.symfony-project.org/jobeet/1_4/Doctrine/en/06). The problem is on index page the system shows to user jobs per category and we have 1+2*N database queries, where N - categories count. This isn't very good, if ...

Handling Constraint SqlException in Asp.net

Hello, Suppose I have a user table that creates strong relationships (Enforce Foreign Key Constraint) with many additional tables. Such orders table .. If we try to delete a user with some orders then SqlException will arise.. How can I catch this exception and treat it properly? Is this strategy at all? 1) first try the delete actio...