sql

SQL data type for physical science measurements - double or decimal

Someone mentioned in this http://stackoverflow.com/questions/1165761/answer post that it's best to use double for physical science computations. Does this apply to measurements such as flash point, viscosity, weight and volume? Can someone explain further? ...

How to manage user and group using DB and PHP?

Hi, We've Web site for software repository for internal team to access it. Currently there are many users and divided into various groups. To manage them, we're using string like binary nos., like '000101' and do check 1's and its position, based on that, we decide user belongs which group(s)... For example, '01111' => group 'test1' ...

mysql three joins

Hi, I have a problem with mysql I have 3 tables: Deposit +-------------------+-------------+------+-----+ | Field | Type | Null | Key | +-------------------+-------------+------+-----+ | id | bigint(20) | NO | PRI | | status | int(2) | NO | | | depositDate | datetime |...

Permissions required to allow arbitrary sql to be executed safely

I want to create an SQL sandbox that will allow users to execute arbitrary SELECT queries at a PostGIS database. Essentially, I want to allow users access to psql to play with. Obviously this is a security disaster if write access is allowed. How can I create a system such that querying data is allowed, but there is no reasonable poss...

How to get updated row's PK_ID

How to get updated row's PK_ID UPDATE [M_RATINGS] SET [RATING] = @rating WHERE [POST_ID] = @postId AND [USER_ID] = @userId; ...

Use stored procedure output parameter

ALTER PROCEDURE dbo.StoredProcedure8 @emp_code bigint, @co_id bigint, @p decimal(8,2) output AS SELECT @p = (select sum(tran_value) from emp_ded_ben_trans where emp_code=@emp_code and co_id=@co_id and period_flg=2 and tax_flg=0) RETURN ...

SQL query based upon some criteria

sir, it like searching function i need to search the table which has data stored in ms access table. i have create a text box for the contract no,username and date and need to search the table according to contract no or username or date. for that i need a coding with solve the problem in single sql command. i have try it with where he...

get all markers within a given radius in sql

I'm trying to get all locations stored in the database with an sql statement described here My sql statement is: SELECT TOP(10) *, ( 6371 * acos( cos( radians(<cfqueryparam cfsqltype="CF_SQL_Numeric" value="#FORM....

SQL INNER JOIN question

Hi, I'm creating a query that will display information for a record which is derived from 8 tables. The developer who originally wrote the query used a combination of 'where this equals this' AND 'this equals this' to create the joins. I have since changed the query to use INNER JOINS. I wondered if my approach was better than utilisin...

Does ISNULL or OR have better performance?

I have the SQL query: SELECT ISNULL(t.column1, t.column2) as [result] FROM t I need to filter out data by [result] column. What is the best approach regarding performance from the two listed below: WHERE ISNULL(t.column1, t.column2) = @filterValue or: WHERE t.column1 = @filterValue OR t.column2 = @filterValue UPDATE: Sorry, I ha...

Resultset closed exception

Hi, I am trying to retrieve results from a DB in a resultset. However i want to execute an update query for each entry in the resultset, but i get an exception. this is my code try { Statement statement = sqlconnection.conn.createStatement(); query = "select * from reminders where year<= "+ syear +" and month<=" + smonth +" ...

Best practice SCRIPT Installation DataBase

Hi I am new at SQL, I would like to have your opinions regarding best practices to adopt in SQL scripting to install a Data Base. PROBLEM A) In my script I have several Batches to create Tables. Tables have many Foreign Keys to each others, at the moment I must arranges batches in the right order to avoid conflict with FK Tables. I woul...

complex group by mysql query

I have a table with the following rows: id. user_id, type - link 1. 555, image - http://1 2. 555, image - http://2 3. 654, image - http://3 4. 245, video - http://.. 5. 555, image - http://.. 6. 878, text - http://.. I want to group the type (image) by date, so they show as single row. In this example, the first two images ...

SQL: how to get more information from a GROUP BY statement

Consider the following SQL statement: SELECT invoice.customer_name, invoice.customer_id, invoice.shop_location, sum(invoice.cost) FROM invoice GROUP BY invoice.customer_name, invoice.customer_id, invoice.shop_location What can be done to the statement to identify which rows would be identical to other rows if it weren't for their i...

Query optimization : Which SELECT syntax is faster?

Hello, Given 5,000 IDs of records fetch in the database, which query , in your opinion is faster? Loop through 5000 IDs using php and perform a SELECT query for each one, foreach($ids as $id){ // do the query $r = mysql_query("SELECT * FROM TABLE WHERE ID = {$id}"); } Or collect all ids in an array, and use SELECT * FROM TABLE...

Big problem with booking system PHP + SQL

Hello, I am creating now a new booking system, the part of the private rooms was done and I have now the part of the Dorm (sharing room). The system works like that: Insert coming day + leaving day + how many persons in the dorm the system checks in the DB (of MYSQL by the way) if the is free room. now how it checks? in the DB has c...

How can I make multiple records to be printed as a single row

This three columns are taken from 3 tables. In other words, these records are retrieved by joining 3 tables. It is basically a very simple time sheet that keeps track of shift starts time, lunch time and so on. I want these four records to show in one row, for example: setDate --- ShiftStarted --- LunchStarted --- LunchEnded ---- ...

SQL: how to use column name from an outer clause in an inner clause?

How can I use the value from an outer clause inside an inner clause using nested SELECT statements? Eg: SELECT cost AS c, quantity, (SELECT COUNT(1) FROM accounts WHERE cost = c) FROM accounts Can c be referenced in the inner SELECT clause as attempted above? ...

Is a CLUSTER INDEX desireable when loading a sorted loadfile into a new table?

INFORMIX-SE: My users periodically run an SQL script [REORG.SQL] which unloads all rows from a table in sorted order to two separate files (actives and inactives), drops the table, re-creates the table, loads the sorted loadfiles back into it, creates a cluster index on the same column I sorted my unload files by, creates other supporti...

Will indexing a SQL table improve the performance of a LINQ statement?

Apologies for what may very well be a stupid question. I'm just intrigued as to (a) will indexing improve performance (b) how will it improve performance and (c) why will it improve performance? Also, if this does improve performance, would this be the case across the board for LINQ to SQL, LINQ to Entities, LINQ to Objects, etc, etc. ...