sql

database partiton Function (sql server 2008)

HI, I want to write partiton in sql server 2008 for my fleet management system. I want to write a partition function such that --values (vehicle number) like for example mh-30-q-126,mh-30-a-126,mh-12-fc-126 should be moved to respective partiton, depending upon middle values like ,q,a,fc respectively My trial function:- CREATE PA...

SQL: Subquery assistance

I'm trying to SELECT two values in one statement instead of two statements. The first statement counts how many entries won for a specific contest that has an id of 18. The second statement counts the total quantity of prizes for that contest. Query 1: SELECT COUNT(*) FROM entries WHERE entries.contest=18 AND entries.won=1 Query...

MySQL syntax group by restaurant with cheaper menu

Hi everyone ! Here is my SQL request on MySQL (MySQL: 5.0.51a). I want have a list of restaurant with his cheaper menu: select r.id, rm.id, rm.price, moyenne as note, get_distance_metres('47.2412254', '6.0255656', map_lat, map_lon) AS distance from restaurant_restaurant r LEFT JOIN restaurant_menu rm ON r.id = rm.restaurant_id wh...

Trying to infer a percentile range

Hello, I have a set of data points that fall within columns. The columns represent the percentile - as in where this result falls in percentile of population. For example: *AgeYears P3 P5 P7 P10* 5 12.1 13.1 14.1 15.5 7 14.1 14.9 15.9 16.9 ...

Problem with update statement

I am trying to update all records in a column so that they start with 'CD' e.g. DCE206 would become CDE206. UPDATE table SET column = REPLACE(column1, 'DC', 'CD') WHERE column1 LIKE 'DC%' I am using the above update statement however the following error appears 'Subquery returned more than 1 value. This is not permit...

How should i perform tree traversal in given structure?

Mission I'm trying to find out the count of children in a set of tables illustrated below. The enviroment is LAMP but help in the right direction via other syntaxes are appreciated. Table structure users ----- user_id parent_id user_meta --------- user_id registration_date user_levels ----------- user_id level This basic struc...

Does XML AUTO support what I am trying to do?

Hi At present we have a denormalised database. ie Name|NameID|EmployeeID|EmployeeType I'm normalising the database to resolve the EmployeeID from the Employee table rather than the Name Table. So we have a select at the moment SELECT Name, NameID, EmployeeID, EmployeeType FROM Name FOR XML AUTO Which will output: <Name Name...

Select Distinct Sql Server Question

I have the following table structure. A | B | C I wish to pull column A and B where all the results of A and B are distinct. I wish to ignor column C. My unerstading of the distinct keyword that it looks at the whole row not jst the columns you return. Any ideas how I could do this? ...

Consolidated: SQL Pass comma separated values in SP for filtering

I'm here to share a consolidated analysis for the following scenario: I've an 'Item' table and I've a search SP for it. I want to be able to search for multiple ItemCodes like: - Table structure : Item(Id INT, ItemCode nvarchar(20)) - Filter query format: SELECT * FROM Item WHERE ItemCode IN ('xx','yy','zz') I want to do this dynamic...

What am I doing wrong: executed an oracle stored procedure from sql server using the open query function.

syntax: EXECUTE ( begin (LUMD_REP_APPGRC.peopledb_T2t.collect_all(SYSDATE - 40, SYSDATE ); end;) AT LUMD; error: Incorrect syntax near the keyword 'begin'. ...

SQL Server Extended Property MS_SubdatasheetName

Our application uses a SQL Server back-end with many stored procedures. Recently, while trying to fix an unrelated problem, we scripted a stored procedure to an ALTER statement to a SQL window to try something. Renaming our proc for testing purposes, we ran the script, and got this perplexing error: Msg 15233, Level 16, State 1, Proce...

DBIx::Class result classes and actual tables

I'm studying DBIx classes and I'm a bit confused since my interaction with a database so far has been plain SQL queries in PHP code. Anyway, as I understand it, the class operates with the schema defined in the result classes instead of interacting directly with the database. The schema can be either be built manually via the various ....

.NET character encoding problems

I've got some problems on a .NET site where both Latin (åäö) and Latvian (āē) characters would need to co-exist. In the database, I'm using nvarchar and ntext for my fields, and if I enter the texts directly into the database, everything works fine. The problem is when I enter the exact same text using a form that does an SQL UPDATE, t...

Java Programming - Where should SQL statements be stored?

Where should an JDBC-compliant application store its SQL statements and why? So far, I managed to identify these options: Hardcoded in business objects Embedded in SQLJ clauses Encapsulate in separate classes e.g. Data Access Objects Metadata driven (decouple the object schema from the data schema - describe the mappings between them ...

How to get the attribute value with XQuery in MS SQL Server 2008

I have an XML like this: <EXP> <TITLES> <SUBTITLE CL="AXT4" FL="1" NB="Text 1"/> </TITLES> <TITLES> <SUBTITLE CL="BVT6" FL="2" NB="Text 2"/> </TITLES> <TITLES> <SUBTITLE CL="PLO7" FL="3" NB="Text 3"/> </TITLES> </EXP> Using XQuery in SQL Server 2008, How can I select Just the value of the attribute NB in a list...

SQL question : How do I pivot mutiple results to single row?

I have table in data base name "train delay, with columns train number(int), DelayTime(int), DelayReason(nchar) so the train may have more than one delaytime for each delay reason, for example: trainnumber,Delaytime,DelayReason 1 ,5 sec ,x 1 ,10 sec ,Z 1 ,70 sec ,TY I want to create a crystal rep...

Dynamic dropdown based on Radio selection

Good morning all! Myself and a co-worker are tasked with a system-wide scripting solution but neither of us are .NET programmers so we need your help. We have a GUI that displays a radio selection box (3 options) that are the three sites where our hospitals are. We need to dropdown located on the form to fill with only the locations bas...

Updating multiple values Mysql

How can i update multiple values in mysql , this didn't work UPDATE test SET list=0, price= 0.00 cprice= 0.00 WHERE test.id =3232 ...

Dynamic Foreign Keys - How To Implement?

I have 4 tables (appointed, class, elected, status) that I want to cross reference into a single table's (members) column. The values of the of 4 tables are time sensitive based off a history table (members_history). The desired result is that the query should output all members and the current appointed position or current elected posit...

Change Large Number of Record Keys using Map Table

I have a set of records indexed by id numbers, I need to convert these record's indexes to a new id number. I have a two column table mapping the old numbers to the new numbers. For example given these two tables, what would the update statement look like? Given: OLD_TO_NEW oldid | newid ----------------- 1234 0987 7698 ...