sql

T-Sql Select * Between 30% and 40%

Question How do I write a T-SQL Stored Procedure that lets me select percentages of rows between X% and Y%? So basically I would want to select the rows between 30 PERCENT and 40 PERCENT..... I know that you can do the following, but obviously that doesn't let met specify a set of rows between 2 percentages. SELECT TOP 50 PERCENT * ...

metadata for determining unsed columns

We are fetching column names from all_tabs_cols, where we get some unused columns that are not present in the table. How can I determine all the unused columns that are present in all_tabs_cols. Does there exists a data dictionary table for this ? procedure xxx_mig_db_column_list_proc is begin insert into xxx_mig_db_column_list ...

how to ensure data consistency

c# application. I am doing a select followed by update of a column in a table. I am putting these in a separate transaction with isolation level set to Serializable. I am doing this to achieve data consistency. But still I can check that multiple users are able to read (select) the same value and eventually trying to update with the sa...

Problem selecting the latest record in JOIN

These are my 2 tables: CREATE TABLE `documents` ( `Document_ID` int(10) NOT NULL auto_increment, `Document_FolderID` int(10) NOT NULL, `Document_Name` varchar(150) NOT NULL, PRIMARY KEY (`Document_ID`), KEY `Document_FolderID` (`Document_FolderID`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=331 ; CREATE TABLE `fil...

Linking "Friends" with the account holders profile

I am designing an application where an account holder has "friends". How would I go about linking those friends to the original account holder? Would an efficient SQL table be something like: AccountHolderID (varChar 20) FriendsID (nText) ...

Administrate a SQL Server 2000 database from Windows and Change a hole column

Hello guys, i have some experience with MySQL but none with SQL Server, i have a computer who host a database (SQL Server 2000) and i have local access to it. The think is that one column of the table NomAntiguedad need to be change from a given date period; I need to multiply by 0.01 all the values of the column between the values of me...

SQL query for finding row with same column values that was created most recently

If I have three columns in my MySQL table people, say id, name, created where name is a string and created is a timestamp.. what's the appropriate query for a scenario where I have 10 rows and each row has a record with a name. The names could have a unique id, but a similar name none the less. So you can have three Bob's, two Mary's, on...

In SQL Server, what's the best way to merge tables from multiple databases?

hi guys, I'm sorry that I can't find a better title of my question. Not lemme describe it in detail. I have 4 database which are a, b, c and d. Database a have all table's that appear in b, c and d, and they have the same structure with the same constraints(pk, fk, default, check). b, c,d just have some tables that appear in a. Now the...

How to increment in a select query

I've got a query I'm working on and I want to increment one of the fields and restart the counter when a key value is different. I know this code doesn't work. Programmatically this is what I want... declare @counter int, @id set @counter = 0 set @id = 0 select distinct id, counter = when id = @id then @counter +...

how to write loop in pl/sql that goes over numbers

I want to write a loop that iterates over numbers 105 102 19 17 101 16 106 107 for each iteration I want to plug the number in a query and insert it into a table. pseudo: LOOP (105 102 19 17 101 16 106 107) FETCH select * from some_table where value=current_iteration_index --105..etc. INTO my_rec_type END LOOP; ...

automatically placing results of a called procedure into a select statement

I'm playing with some code from an article written by Peter Brawley found here on page 6 of the pdf. I'm trying to figure out how to automate it so that the result of the procedure is automatically placed in the select query. Right now what I am doing is calling the procedure, exporting the result into a text file, going to the text fi...

SQL: break up one row into many (normalization)

I am in middle of upgrading from a poorly designed legacy database to a new database. In the old database there is tableA with fields Id and Commodities. Id is the primary key and contains an int and Commodities contains a comma delimited list. TableA: id | commodities 1135 | fish,eggs,meat 1127 | flour,oil In the new datab...

Optimal MySQL temporary tables (memory tables) configuration?

Hello, excuse my english First of all, I am new to optimizing mysql. The fact is that I have in my web application (around 400 queries per second), a query that uses a GROUP BY that i can´t avoid and that is the cause of creating temporary tables. My configuration was: max_heap_table_size = 16M tmp_table_size = 32M The result: temp ...

RDL is it possible to have optional parameter or force default value to null

I need to have an optional parameter or a parameter that's default value is null. I want to use a dropdown list for a report, the list is getting it's values from another dataset. I have selected the option to allow NULL values. I have tried setting the default value to null and all the other settings available. Is there some way to ma...

Using SQL Will Fix Concurrency Issues?

I am developing a set of applications that all hit the same database, and concurrency has been one of the biggest issues I've had to deal with. I'm developing solutions to work around these issues, and I recently thought of using SQL queries instead of LINQ queries to update databases. Because SQL has pessimistic concurrency control, ...

Grouping data in memory using Linq To Objects or using native SQL -- WHICH IS FASTER?

I noticed that LINQ to Objects has a GroupBy method. In light of this, I was wondering if anyone can build a case for group list of objects in memory using LINQ vs having SQL Server perform the grouping? ...

LINQ 2 SQL Return Multiple as Single String

I have a 1 to Many relationship between tblBusiness and tblPhone. For a specific BusinessID I am trying to return a single string of information to bind to a textbox. Below is my latest attempt along with the Generated SQL from that same LINQ. No matter WHAT I have tried it returns NULL unless there is a value for all 3 fields. What ...

ASP.NET Form Builder?

I have a number of departments that need to put forms online...I'm wondering if there is a way for me to allow them to do this dynamically - rather than me programming each form? It does need to flow into a database...I'm thinking something similar to Wufoo? ...

LINQ And Concurrency Question

I am developing three applications that all share a common database. I'm running into many different concurrency issues and was wondering if it is possible to prevent any other queries to execute when certain queries are running (in other words, locking the database so there won't be any concurrency issues). Edit: I'm using LINQ to SQ...

SQL Return Random Numbers Not In Table

I have a table with user_ids that we've gathered from a streaming datasource of active accounts. Now I'm looking to go through and fill in the information about the user_ids that don't do much of anything. Is there a SQL (postgres if it matters) way to have a query return random numbers not present in the table? Eg something like this:...