sql

How can I protect this code from SQL Injection? A bit confused.

I've read various sources but I'm unsure how to implement them into my code. I was wondering if somebody could give me a quick hand with it? Once I've been shown how to do it once in my code I'll be able to pick it up I think! This is from an AJAX autocomplete I found on the net, although I saw something to do with it being vulnerable to...

Should I write more SQL to be more efficient, or less SQL to be less buggy?

I've been writing a lot of one-off SQL queries to return exactly what a certain page needs and no more. I could reuse existing queries and issue a number of SQL requests linear to the number of records on the page. As an example, I have a query to return People and a query to return Job Details for a person. To return a list of people...

What is happening in this T-SQL code? (Concatenting the results of a SELECT statement)

I'm just starting to learn T-SQL and could use some help in understanding what's going on in a particular block of code. I modified some code in an answer I received in a previous question, and here is the code in question: DECLARE @column_list AS varchar(max) SELECT @column_list = COALESCE(@column_list, ',') + 'SUM(Case When Sku...

SQL Server 2008 Table Maintenance - Rebuild, Reorganize, Update Stats, Check Integrity etc HELP!

I'm migrating a ~15GB database from SQL Server 2005 to a new server running SQL Server 2008, and along with that I need to create all the new Maintenance Plans. I can take care of all the backup stuff, but the table maintenance baffles me some. Does anyone have any input on how often I should (or how often you do would suffice too) the...

Change the precision of all decimal columns in every table in the database

Hi all, I have a rather large database that has alot of decimal columns in alot of tables, the customer has now changed their mind and wants all the numbers (decimals) to have a precision of 3 d.p. instead of the original two. Is there any quick way of going through all the tables in a database and changing any decimal column in that t...

Selecting data from SQL Server table according to Month

I have to come up with a way to get data from a SQL server table given it's month There's a smalldatetime type field called "date" in the "events" table and a field from it looks like this: 29/01/2003 17:00:00 It should be one among those that appear in the gridview when I select jan/03 in a given DropDownList control in ASP.NET. Wh...

SQL Server 2008 - Shrinking the Transaction Log - Any way to automate?

I went in and checked my Transaction log the other day and it was something crazy like 15GB. I ran the following code: USE mydb GO BACKUP LOG mydb WITH TRUNCATE_ONLY GO DBCC SHRINKFILE(mydb_log,8) GO Which worked fine, shrank it down to 8MB...but the DB in question is a Log Shipping Publisher, and the log is already back up to some 5...

select, delete & update from multible tables using a single query in mysql

for example i use following command to find a record SELECT `users`.`mail` FROM `users` WHERE `users`.`uid` = %s if found an match, then i should like to delete this record, and update in the same query an another table. i can solve this with 'joins' ? ...

SQL Joining Two or More from Table B with Common Data in Table A

NOTE: EDITED The real-world situation is a series of events that each have two or more participants (like sports teams, though there can be more than two in an event), only one of which is the host of the event. There is an Event db table for each unique event and a Participant db table with unique participants. They are joined together...

how to search data between specified dates

I have a query OleDbCommand com = _ new OleDbCommand("select * from techs where actd0v between '" + _ TextBox1.Text + "' and '" + TextBox2.Text + "'" , con); where textbox 1 and 2 are the specified dates in which I want to retrieve some date related to those dates. But when I'm trying to find the data between...

How can I do a left outer join where both tables have a where clause?

Here's the scenario: I have 2 tables: CREATE TABLE dbo.API_User ( id int NOT NULL, name nvarchar(255) NOT NULL, authorization_key varchar(255) NOT NULL, is_active bit NOT NULL ) ON [PRIMARY] CREATE TABLE dbo.Single_Sign_On_User ( id int NOT NULL IDENTITY (1, 1), API_User_id int NOT NULL, extern...

How to find missing alpha values in sets of data within same table in SQL

I have a table of many values where one column has the WO Number, and another column has the Resource ID. I need to be able to find all the WO numbers that do not have a resource value of "RW". Here is an example of the typical information. I need to be able to know that work order 5678 does not have an "RW" Resource ID. WO Number - ...

Data Import in SQL Server Express

SQL Server Express does not have the Tasks -> Import Data option that other editions of SQL Server has. Has anyone come across a free tool to import data? I understand I can use the bulk import but I have run into a security issue with it and would like a quick and a dirty way of importing a csv file to a sql express table. ...

Complex SQL Query similar to a z order problem

I have a complex SQL problem in MS SQL Server, and in drawing on a piece of paper I realized that I could think of it as a single bar filled with rectangles, each rectangle having segments with different Z orders. In reality it has nothing to do with z order or graphics at all, but more to do with some complex business rules that would ...

What is the Reason large sites don't use MySQL with ASP.NET?

I have read this article from High Scalability about Stack Overflow and other large websites. Many large high traffic .NET sites such as plentyoffish.com, MySpace and Stack Overflow all use .NET technologies and use SQL Server for their database. In the article it says a source in Stack Overflow said: As you add more and more databas...

sql query to get the sql server 2005

i have table with filmname and actors column in sql server 2005 i want the sql query to get all the actors of the film starred by both "bradpitt" and "rusellcrowe" the table design is as follows CREATE TABLE [dbo].[mytable]( [actors ] [nchar](10) NULL, [filmname] [nchar](10) NULL, ) ON [PRIMARY] ...

Ordering of month/year pairs in T-SQL query

I am writing a stored procedure for displaying month and year. It is working, but it is not returning the rows in the desired order. ALTER procedure [dbo].[audioblog_getarchivedates] as begin select DateName(Month,a.createddate) + ' ' + DateName(Year,a.createddate) as ArchiveDate from audio_blog a group by DateName(Month,a.creat...

How to detect if a string contains special characters?

How to detect if a string contains special characters like #,$,^,&,*,@,! etc in SQL server 2005? ...

Charater string buffer too small

I have select: select v.accs, v.currency,v.amount,v.drcr_ind, count(*) qua,wm_concat(ids) npx_IDS, wm_concat(px_dtct) npx_DTCT from table v group by accs, currency, amount, drcr_ind but i get error ORA-06502: PL/SQL: : character string buffer too small if i'll remove one string, because sometimes (when v.accs= 3570) count(*) = 215 bu...

How to detect if a string contains atleast a number?

How to detect if a string contains atleast a number (digit) in SQL server 2005? ...