sql

How to get order output after using group in the sql query?

Hi, I have a my sql table with customer names and orders that they placed over time. table column names are id, customer name, order value, status, and created and modified. I am able to group customer names and number of orders. using a sql query like this.. SELECT Customer,count(OrderPrice) FROM Orders GROUP BY Customer It work...

Is there a portable way to have "SELECT FIRST 10 * FROM T" semantic?

I want to read data in blocks of say 10k records from a database. I found Result limits on wikipedia and it seems obvious that this can't done with sql in a portable way. Another approach could be JdbcTemplate which offers many methods for queries, but how could I decide that enough rows have been read. Through the callbacks like RowMa...

Saving SQL in Visual Studio 2010

Is there a way to have Visual Studio 2010 save the SQL you've developed in the SQL Editor to the current solution? ...

Floating point problem in SQL Server 2005

The code below is used to calculate the miles between two cities. In this case, it's for the distance from Yarmouth, ME to Yarmouth, ME - obviously zero - meaning that results for cities within X miles of Yarmouth should include Yarmouth itself. The problem is that the latitude and longitude for Yarmouth seem to be causing some kind of ...

SQL join on a table using freetext SQL server 2005

Table A has columns question varchar(200) objective varchar(200) Table B has columns + a fulltext index solution varchar(max) I am trying to output a flat merge of these matching a.objective with the TOP 5 solutions from Table B for the keywords in A.objective. where freetext(text,A.objective) e.g. "question one", "objective one",...

Is there a tool to build a relationship tree of the stored procedures and functions used in SQL Server 2008?

I have a legacy data-driven application with an extremely complicated data model (and hundreds of SQL stored procedures and functions with no clear delineation of responsibility) in SQL Server 2008. We have both web app and reporting stored procedures and they are supposed to live side-by-side but there are examples where this rule wasn...

SQL incrementing help

1. Name---ID--- SEQ 2. *---------101--1 3. *---------101--2 4. *---------101--3 5. *---------999--1 6. *---------999--2 Iqnore the -'s What im importing is Name, ID, and other fields. What im trying to assign is SEQ. I'm not sure how to reset a count when I get to the 2nd group. Im using MS SQL Server 2005 ...

How would you implement a very wide "table"?

Let's say you're modeling an entity that has many attributes (2400+), far greater than the physical limit on a given database engine (e.g. ~1000 SQL Server). Knowing nothing about the relative importance of these data points (which ones are hot/used most often) besides the domain/candidate keys, how would you implement it? A) EAV. (boo....

LTRIM usage with SQL server 2005

I am a bit of an sql noob so please forgive. I can't seem to find a usage example of LTRIM anywhere. I have a NVARCHAR column in my table in which a number of entries have leading whitespace - I'm presuming if I run this it should do the trick: SELECT LTRIM( ColumnName) From TableName; Will this give the desired result? ...

How to check for a substring in a column, using CASE /IF (SQL querying)

I need to return one of 2 values for certain conditions: My different cases are: when one column has 'substring' on the right end, return that column. (i.e. LIKE '%substring') Else return other column (from other table) This works: SELECT * From Table1 where col1 is not null and col1 like '%substring' However, this doesn't work: ...

How do I search "many LIKE" in the database (mysql)?

I want to search number of strings in the Database (type: MYSQL) and I did this: SELECT * FROM `rooms` WHERE `dates` LIKE '%09/08/10%' OR '%08/08/10%' Why doesnt it work? when I removed the part of OR '%08/08/10%' it was working well, I think I use it not good. How should I do it? ...

SQL - How can I temporarily protect the data in this table?

I am populating a table that acts as a cache. (This is needed because the data comes through a linked server and joins through the link are too expensive) I've included pseudo code below that hopefully demonstrates what I'm trying to do. I really don't know if there's a way to lock a table down like this, or if I need to use transaction...

Best way to prevent Update

Hi All, I have a situation where we want to prevent the update of a table for a specific scenario. So for 95% of the updates I would want the update to flow through as normal and update the desired fields....for that other 5% I want to prevent the update from happening. This will be based on data passed in the update along with what i...

MySQL unknown column

Hi, Why am I getting this error: 1054 - Unknown column 't.type' in 'field list' I have a column called type in my table. And I've got the table 'tester' using an alias t. SELECT y.*, (SELECT COUNT(*) FROM (SELECT *, CASE t.type WHEN 'Advanced' THEN t.t...

How can I export data from my table to a sql file?

I'm using SQL Server 2005 and I want to export all records from my Employee table to a .sql file. But when I run the export data option, it only generated the script of the structure of the Employee table, it does not contain the records on it. What i want is to generate a script that will contain an INSERT statement containing the val...

SQL Server 2005 XML to table

I'm using classic asp and I'm passing in a varchar (ado data type) into an xml data column in a proc. The xml looks as follows: <DocumentCriteria> <Document documentGUID="{B49654E7-9AF2-4B89-AF8F-5146F7CD4911}" graderFYC="5907"> <criterion cnumber="1" rank="3"/> <criterion cnumber="3" rank="3"/> </Document> </Docume...

Error with mysql procedures ERROR 1304 & ERROR 1305

I am new to using procedures and cannot seem to get mine working. I am using MySQL v5.1.36 and inputing my code using MySQL Console on a WAMPP server. If I go to (re)create the procedure. I get error #1304 (42000). mysql> DELIMITER // mysql> mysql> CREATE PROCEDURE modx.getCRID (IN x VARCHAR(255),OUT y INT) -> BEGIN -> ...

Self Join and Iterative SQL

Sample Table Emp Id Emp Name Manger Id 1001 arun 1004 1002 Bharath 1004 1003 Chitra 1004 1004 Devi 1005 1005 Eli 1006 1006 Fatima 1007 1007 Ganesh 1008 when i select manager id 1004 it should display three names arun,bharath,chitra and if i select 1005 it should display devi,arun,bharath,chitra FY...

What is the max length of a varchar (doctrine:string) in Doctrine 2 or SQL?

if i use a string type in doctrine 2 (maps to sql varchar), what is the max length i can use? ...

In SQL Server 2008, how should I copy data from database to another database?

I'm trying to write a stored procedure to copy a subset of data from one set of tables to an identical set of tables in a different database. The "source" database needs to be a parameter to the stored procedure. I've struggled with this for two days now, and I thought I had a good solution: Validate that the schemas are the same. Cr...