sql

What would be a reliable way to get fractional value from a number?

I have a number of type Decimal(8, 2) and have been using Substring to get fractional value. E.g.) declare @val decimal(8, 2), @strVal varchar(10) set @val = 15.80 set @strVal = cast(@val as varchar) select @val, substring(@strVal, charindex('.', @strVal), len(@strVal)) Is there a better way to simply get fractional value, .80 fro...

sql COUNT function returns an array instead of mysqli object?

I want to count some rows in my database and I'm using the following code: $tagname = Person; $query = "SELECT COUNT(thread_tag_map.tag_id) AS tagcount FROM tags, thread_tag_map WHERE thread_tag_map.tag_id = tags.id AND tags.name = '$...

Check sql script valid

As part of a release we run a load of PL/SQL scripts against a database. Recently someone left the ; off the end of a line in one script that was called another script so this meant that script did not get run. Because this did not cause an error, it just didn't get run, it took quite a while to track down what had happened. I want to c...

Efficient Pagination from Join in Django

Hi. I've got a problem here with a join and pagination. I have 3 Models: Pad Tag TagRelation I use Tag relation to manage a ManyToMany relationship betweent Pads and Tags (with the through attribute of te ManyToMany field). Now when i do a join on the Pad and Tag tables it gives me something like this... pad.name tag.name etc ...

Saving order preference in SQL

I am trying to see what is the best way to handle the following scenario I have a table called, lets say User, and i have a table called items. Each user can have multiple items added to his account. I have another table , lets say AssociateItem, which maintains the association between user and the items. (links UserID to ItemID). A us...

Method for matching any string in SQL

I have a simple SQL query, SELECT * FROM phones WHERE manu='$manuf' AND price BETWEEN $min AND $max The issue is that all of the variable fields are connected to fields that will sometimes be empty, and thus I need a way to make them match any value that their respective field could take if they are empty. I tried $min=$_REQUEST['min...

FTS: Searching across multiple fields 'intelligently'

Hi, I have a SP using FTS (Full Text Search). I want searches across multiple fields, 'intelligently' ranking results based on the weights I assign. Consider a search on a view fetching data from tables: Book, Author and Genre. Now, I want the searcher to be able to do: "Ludlum Fiction", "Robert Ludlum Bourne", "Bourne Ludlum", etc....

How do I protect this function from SQL injection?

public static bool TruncateTable(string dbAlias, string tableName) { string sqlStatement = string.Format("TRUNCATE TABLE {0}", tableName); return ExecuteNonQuery(dbAlias, sqlStatement) > 0; } ...

How to see which queries has been executed. (mysql)

Hi, I run a site at localhost and i would like to see which queries are executed. I've seen that some pages execute a lot of queries (eg 107) and i would like to see which are all these,as i think they're a lot.. (i know how many queries are executed, as the queries are executed through a function which also stores at a global value the...

Sql Get the last 6

...

Update query "updatable query" issue

In Access 2003, I'm trying to take a table and if any Indicator = 1 for ANY line of a given ID, make all lines = 1 for that ID For Example, if we have: ID Indicator Jack 0 Jack 0 Jeff 1 Jeff 0 Mark 1 Mark 1 Would become: ID Indicator Jack 0 Jack 0 Jeff 1 Jeff 1 Mark 1 Mark 1 Since both Jeff and Mark have at least 1 line with...

Cannot find data after commiting in PL/SQL procedure?

Hello, I have code snippet in my PL/SQL procedure that does the following: INSERT INTO payment_operations (id, subscriber, amount, description) VALUES (payment_id, 1234, 5, 'Test'); COMMIT; SELECT subscriber INTO test_subscriber FROM payment_operations_view WHERE id = payment_id; After this I get an exception "no_data_found"! Howeve...

How to assign correlative numbers to rows only using SQL?

I have the following table in an Oracle database: InvoiceNumber InvoiceDate InvoiceCorrelative ------------- ----------- ------------------ 123 02-03-2009 0 124 02-03-2009 0 125 02-04-2009 0 126 02-04-2009 0 127 02-...

How to resolve Oracle error ORA-01790?

I have two select statements joined by "union". While executing that statement I've got: Error report: SQL Error: ORA-01790: expression must have same datatype as corresponding expression 01790. 00000 - "expression must have same datatype as corresponding expression" Maybe you can give me an advise on how to diagnose this problem? ...

can this be written with an outer join

The requirement is to copy rows from Table B into Table A. Only rows with an id that doesn't already exist, need to be copied over: INSERT INTO A(id, x, y) SELECT id, x, y FROM B b WHERE b.id IS NOT IN (SELECT id FROM A WHERE x='t'); ^^^^^^^^^^^ Now, I was trying to write this with an outer join ...

Scrabble board to board.

Is it best to communicate between two scrabble boards on separate computers by creating a cloud with a SQL table, simulating the board. And every time I move is made you contact the server and update the local board? ...

sql server 2005 tsql abs doesn't like decimals?

trying to run the following statement in sql mgmt studio declare @rick as decimal(13,3) @rick = -.5 select bob = abs(@rick) any ideas why this won't work? ...

Joining tables based on the maximum value

Here's a simplified example of what I'm talking about: Table: students exam_results _____________ ____________________________________ | id | name | | id | student_id | score | date | |----+------| |----+------------+-------+--------| | 1 | Jim | | 1 | 1 | 73 | 8/1/09 | | 2 | Joe | ...

How do you retrieve the new keys from an INSERT INTO SELECT FROM query?

Is there a way to retrieve all the keys of the newly inserted records when using an INSERT INTO ... SELECT FROM query? ...

Does SQL Server even look at a table when joining on a variable that returns false?

If I join table A to table B like this... select A.* from A left outer join B on A.Id = B.aId and @param = 'someValue' and @param does not equal 'someValue', does SQL Server even attempt to match records from table B or is it smart enough to know the condition will never be true? ...