I want to update the top 100 records in SQL Server. I have a table T1 with fields F1 and F2. T1 has 200 records. I want to update the F1 field in the top 100 records. How can I update based on TOP …
Can I add a UNIQUE constraint to a PostgreSQL table, after it’s already created?
I have the following table: tickername | tickerbbname | tickertype ————+—————+———— USDZAR | USDZAR Curncy | C EURCZK | EURCZK Curncy | C EURPLN | EURPLN …
How To Do Percent/Total in SQL?
I have an typical CUSTOMER/ORDERS set of tables and I want to display the total percentage of sales a particular customer is responsible for. I can get the total number of orders in the system like so: And I can get the the total number of orders made by the customer like so: How can I combine these into a
Function vs. Stored Procedure in SQL Server
I’ve been learning Functions and Stored Procedure for quite a while but I don’t know why and when I should use a function or a stored procedure. They look same to me, maybe because I am kinda newbie …
SQL Server table creation date query
How can I get the table creation date of a MS SQL table using a SQL query? I could not see any table physically but I can query that particular table. Answer For 2005 up, you can use I think for 2000, you need to have enabled auditing.
Sql Query to Linq
How would I convert this query from SQL to Linq: Update Thanks Guys, this is the code I used. Tested and returns the same as above: Answer I don’t know if the syntax is correct (especially the last two lines) but it should be pretty close. I added the 0 between group and by based on Eamon Nerbonne’s correction in
How do I calculate a running total in SQL without using a cursor?
I’m leaving out all the cursor setup and the SELECT from the temp table for brevity. Basically, this code computes a running balance for all transactions per transaction. Inspired by this code from an answer to another question, I was wondering if SQL had the ability to sum numbers in the same way it’s concatonating strings, if you get my
Column name or number of supplied values does not match table definition
In SQL server, I am trying to insert values from one table to another by using the below query: delete from tblTable1 insert into tblTable1 select * from tblTable1_Link I am getting the following …
Dynamic order direction
I writing a SP that accepts as parameters column to sort and direction. I don’t want to use dynamic SQL. The problem is with setting the direction parameter. This is the partial code: Answer You could have two near-identical ORDER BY items, one ASC and one DESC, and extend your CASE statement to make one or other of them always
Oracle SQL escape character (for a ‘&’)
While attempting to execute SQL insert statements using Oracle SQL Developer I keep generating an “Enter substitution value” prompt: I’ve tried escaping the special character in the query using the ” above but I still can’t avoid the ampersand, ‘&’, causing a string substitution. Answer the & is the default value for DEFINE, which allows you to use substitution variables.