sql

Preventing SQL Injection in SQL Server TEXT fields using Classic ASP

I've got code in ASP that puts values into a Text field in SQL Server using parameterized queries. I was wondering if parameterizing is enough, or if I have to search the field for potential commands, replacing single ticks with double ticks,etc. The text fields are essays, so they might have any number of words or characters. Am I safe...

Is there a way to increment the value of a sql column without reading it

Hello, I wanted to know if there is a way I can directly increment the value of a column without reading the current value. something like: update table `user` set cnt = cnt+1 The above statement gave me a syntax error, but I am sure there has to be something for it. Thanks ...

Do I need to use multiple column SQL Server index in the same order as I declare it?

When I declare a clustered index, specifying: column1, column2 and column3 in this order - do I need to use the columns in that same order? For example, will this use the clustered index mentioned earlier to update multiple rows: UPDATE Table1 WHERE column3 = 1 AND column2 = 1 AND column1 = 1 ...

help with a sql query

(newbie, help if you can please) hi, i could use some help writing a SQL query. i'm trying to display some data from one table but the data i need depends on a value from a different table. i'm pretty new to this so i will try to explain this the best i can: i have an 'Orders' table with a 'ShipCity' and 'OrderId' columns. i would like...

Postgres EXPLAIN ANALYZE is much faster than running the query normally

I'm trying to optimise a PostgreSQL 8.4 query. After greatly simplifying the original query, trying to figure out what's making it choose a bad query plan, I got to the point where running the query under EXPLAIN ANALYZE takes only 0.5s, while running it normally takes 2.8s. It seems obvious then, that what EXPLAIN ANALYZE is showing me ...

Copy substring of one column and copy to another.

This is a bit above my level. But am trying to learn. I don't want to seem like I'm just trying to get my homework done but would appreciate any help pointers. I am trying to find a substring (postcode) in an address column and once found, copy to the post code column I have the following sql which finds columns that match a postcode pa...

Opposite of inner join

What will be the opposite of inner join? For a table table Person (int PersonId, varchar PersoName, int AddrId), I want to know the rows in Person with bad AddrId which don't have a row in the Address table. ...

SQL Server 2005 where condition with string comparison

I am using SQL Server 2005 with the following query SELECT * FROM EMPLOYEE WHERE EMP_NAME = 'ABCD' It gave me the proper results and when i tried the same query with 'ABCD ', then also it gave me the same result!!! I feel it should not give any results as there is no employee with name 'ABCD ' Or "WHERE" condition works like thi...

Help with a SQL Query

(newbie, help if you can please) hi, i could use some help writing a SQL query. i'm trying to display some data from one table but the data i need depends on a value from a different table. i'm pretty new to this so i will try to explain this the best i can: i have an 'Orders' table with a 'ShipCity' and 'OrderId' columns. i would like...

Between .. and clause in sql server?

hi, in my web application i am displaying videos of user, I want to display the videos which are between 30 days only. Videos that are uploaded last 30 days only. i write query like this but it is not working fine.. select * from videos where posteddate between getdate()-30 and getdate() order by posteddate desc can u he...

Deleting many rows without locking them

Hello good people. In PostgreSQL I have a query like the following which will delete 250k rows from a 1m row table: DELETE FROM table WHERE key = 'needle'; The query takes over an hour to execute and during that time, the affected rows are locked for writing. That is not good because it means that a lot of update queries have to wait ...

How to sort string in sql server

How to sort this data in sql server as Pre-OP 1, Pre-Op 2 like wise Pre-OP 1 Pre-OP 10 Pre-OP 11 Pre-OP 12 Pre-OP 13 Pre-OP 14 Pre-OP 15 Pre-OP 16 Pre-OP 17 Pre-OP 18 Pre-OP 19 Pre-OP 2 Pre-OP 20 Pre-OP 21 Pre-OP 22 Pre-OP 23 Pre-OP 24 Pre-OP 25 Pre-OP 26 Pre-OP 27 Pre-OP 28 Pre-OP 29 Pre-OP 3 Pre-OP 30 Pre-OP 4 Pre-OP 5 Pre-OP 6 Pre-OP...

SQL query based on criteria

it's working if all the feilds is entered by user. i need a code that combine all the sql command. user may enter in the one field or two field or all the three fields. i need to search the database with one field query or two feild query or three feilds query. i have try it with where help is a table & search-test is form & contract no...

What is the difference between these three Oracle datatypes?

char varchar varchar2 I understand that varchar2(10) will allocate space dynamically upto 10 bytes. char(10) will allocate 10 bytes at the beginning and fill it with junk if the actual datalength is less. If this is correct, what does varchar(10) do? ...

Avoid NULL columns using DEFAULT Empty String

Hi, how can I create a Column with the default value being an empty string? thanks guys! ...

Safest way to get last record ID from a table

In SQL Server 2008 and higher what is the best/safest/most correct way to retrieve the ID (based on autoincrementing primary key) out of the database table? to retrieve the value of the last row of some other column (like, SELECT TOP 1 FROM Table ORDER BY DESC)? ...

SQL Server 2005 HTTP Endpoint Authentication

Is there any way of setting up an endpoint that does not require Integrated Authentication or HTTPS - either basic username / password authenticaion or none at all??? ...

Incorrect SQL Syntax - Unclosed quotation mark after the character string

Now i have string a = "Unclosed quotation mark after the character string '%Bamboo.Widgets.RequestApproval.CollectTask ORDER BY Date DESC'. Incorrect syntax near '%Bamboo.Widgets.RequestApproval.CollectTask ORDER BY Date DESC'." for filter I'm using replace ("'","''") replace ("%","[%]") replace ("[","[[]") a...

How to make the Order by statement for Two fields in a single query and one field needs to DESC and one field needs to ASC using Mysql?

Hello friend, I want to make a query that will give the result on order by using two columns. I made query like this. select el.*, lb.LabName,lb.LabType, lb.LabDescription from encounterlab el INNER JOIN labs lb ON lb.LabType=el.LabType where PatientAcctNo=4 ORDER BY el.DataOfService,lb.LabName DESC It ...

Best practice Date and Time registration

Hi, I am building a simple CMS to manage articles. My MS SQL Server 2008 is Hosted in USA, Author of Data Base are situated in USA and Germany. When a Author create an article in the DataBase I would like record the DATE of creation. I would like to show the date on the website as would all contents and articles are created from German...