sql

SQL SELECT to get the first N positive integers

I need to get a result set containing the first N positive integers. Is it possible to use only standard SQL SELECT statement to get them (without any count table provided)? If it's not possible, is there any specific MySQL way to achieve this? ...

DLookup in Access not running until textBox clicked on in Form

...

control SQL Server database stop/start

Hello everyone, I am using SQL Server 2008 Enterprise. I want to know how many different ways or different reasons why database (not instance, not server, but database) is stopped/started. I am analyzing SQL Server logs. Currently as far as I know, two possible ways/reasons are -- taking database offline/online and stop/start instance/...

Condition in a recursive query

I have the following recursive table-valued function in MS SQL, in order to retrieve a hierarchy of objects from the database: WITH tmpField (ParentNum, ChildNum, FieldNum, FieldDescr, Iteration) AS ( SELECT Field.ParentNum, Field.ChildNum, Field.FieldNum, Field.FieldDescr, 1 FROM Field WHERE Field.ParentNum = @ParentNum UNION...

USING THE SQL LIKE OPERATOR WITH %%

I had a requirement to create a query in MS SQL where the search condition would include/exclude a table based on user input. Say I have two tables’ TABLE_A and TABLE_B with columns KEYCOLUMN_A, COLUMN_A in TABLE_A and columns FKCOLUMN_B, COLUMN_B in TABLE_B And a query like SELECT TABLE_A.* FROM TABLE_A, TABLE_B WHERE TABLE_A.KEYCOLU...

Find and replace LIKE sql data

I'm tring to run a find and replace query on some sql data using Management Studio. I basically want to remove the word FREE from any content. I tried running this query; UPDATE Table_1 SET ContentDetails = REPLACE(ContentDetails, 'FREE', '') WHERE (ContentDetails LIKE '%FREE%') But I get an error saying that data...

Conversion failed when converting from a character string to uniqueidentifier.

Created a stored procedure in SQL 9 (2005) and have since upgraded to SQL 10 (2008). Since then, the following stored procedure has stopped working and thrown up the above error: ALTER PROCEDURE [dbo].[GetModifiedPages] @vPortalUID nvarchar(32) = '' AS BEGIN -- Convert GUID to UI DECLARE @nPortalUID AS uniqueidentifier ...

Calculate hash/checksum in Informix SQL

I would like to calculate some sort of hash or checksum value for a column value in Informix SQL. The problem: We need to anonymize personal information in test data, and would like to do so by hashing the relevant values, as in: UPDATE personal_data SET name=HASH(name), employee_no=HASH(employee_no) We want to use a hash, rather th...

How to store more than 255 char in MySQL database?

I only get set the text field in MySQL to 255, if I want to store a data longer than 255 chars, what can I do? ...

Easier way to insert a long array into an INSERT query?

I'm trying to insert this array into a database: Array ( [0] => 1 [1] => 2376 [2] => 1804229942 53 [3] => 99 [4] => 120510105 5525 [5] => 99 [6] => 21581237 622 [7] => 99 [8] => 46612404 3 [9] => 99 [10] => 174284497 8 [11] => 99 [12] => 200000000 922 [13] => 99 [14] => 13641206 5 [15] => 99 [16] => 118438707 15 [17] => 99 [18] => 20000...

MySQL: How to get user with most wins?

I have a table with the following fields: id, opp1, opp2, opp1_votes, opp2_votes. If one of the opps have more votes than another so we consider that he won. How can I get opp with most wins from this table? ...

SQL Select unique value in a column

I have a table like this: ID CatID Filename 1 1 abc 2 2 abc 3 3 cat 4 2 dog 5 1 dog What I want to do is get just 1 ID per filename. I dont mind what ID i get i.e. the first or the last. How would I go about doing this? ...

Enhance performance of large slow dataloading query

I'm trying to load data from oracle to sql server (Sorry for not writing this before) I have a table(actually a view which has data from different tables) with 1 million records atleast. I designed my package in such a way that i have functions for business logics and call them in select query directly. Ex: X1(id varchar2) x2(id varch...

How to get the biggest differences between two fields comparing all users?

I have a table that has the columns skill1xp, skill1lvl, and skill1rank for 25 skills. Each day I update it for all users, so there's a datetime column. I'm making a high-scores progress tracker for a game, for many users, and I've got just one feature left, which is Highest Gains for a certain period of time (day/week/month). I guess t...

extending dotproject

Actually i am trying to use dotproject to build my own small application. I am stuck up at a point where dotproject displays all the tasks related to a particular project .It queries the database for this firing the sql below $q->addJoin('tasks', 't1', 'projects.project_id = t1.task_project'); $q->addQuery('com.company_name AS com...

How to unlock user account in SQL Server 2005 Management Studio?

One of user name tried login many times and failed. Sql server 2005 locked account automatically. How can I unlock user account in SQL Server 2005 Management Studio? ...

How (and where) should I combine one-to-many relationships?

I have a user table, and then a number of dependent tables with a one to many relationship e.g. an email table, an address table and a groups table. (i.e. one user can have multiple email addresses, physical addresses and can be a member of many groups) Is it better to: Join all these tables, and process the heap of data in code, Use ...

SQL Query List Those that are higher than average

I have 2 tables in the following format: employee (employeeID, EmployeeName, DepartmentID) departments (DepartmentID, DeptName) How many employees there are who work in each of the departments that have more employees than the average number of employees in a department. im looking to the results in the following format: Dept Name...

What is the accepted method to delete records referenced by a junction/join table?

I have three tables as follows (please forgive the loose syntax), with NO cascading relationships (I do not want this, as the database is primarily managed by NHibernate). Invoice ( entity_id int not null, ... ) Ticket ( entity_id int not null, ... ) InvoiceTicket ( InvoiceId --> Not-null foreign key to Invoice.ent...

SQL server compare tables and update if changed

Hi I am looking for A solution to update values in table1 only if the values change. I mean compare to tableb and update only the changed values ...