sql

How does one modify all DB column data based on current data?

In my particular case, we've got a db table that, among other fields, has an "Image" field. We'd like to append ".jpg" to every row in this table for this column. To keep it simple we'll say it just has two columns...an ID column and an Image column. (bonus points for skipping rows that have an empty string for "Image".) The question...

Compile error:Argument not optional

Compile error:Argument not optional I am getting the above error while executing the following query: DoCmd.RunSQL = "insert into tblContract (Empid,testid,Start1,Finish1,Store1,Start2,Finish2,Store2 )values ('" & Me.txtEmpNo.Value & "','" & Me.txtAutoNumber.Value & "','" & Me.txtContSunStart1.Value & "', '" & Me.txtContSunFinish1.Val...

find the tables has binary data

How to find what are all tables has binary data and display the table name ? ...

Selecting Indexes based on Column/Table Names

Hi All, Is there a system SP or dmv that allows me to select indexes in my DB based on columns and table names? What I am trying to do is to drop indexes based on columns with string datatypes as I am in the process of altering my collation settings. Thanks. ...

Using Access 2003 ADP/Project files to access SQL Server 2005 database

We use Access Project files to connect with SQL Server. Our SQL Server 2000 has been upgraded to SQL Server 2005 and now my project files are reporting an incompatibility and the error "This recordset is not updatable" when trying to modify data. So: 1) Will upgrading to Access 2007 and then creating project files solve this problem? ...

Optimize SQL Query

Dear Friends i m using the following which Execute against 1'500'000 rows My SP is as follows: CREATE Procedure USP_12(@AuditMasterID as varchar(10),@TABLE as Varchar(50)) as BEGIN Declare @SQLStatement varchar(2000) Declare @PrefixNo varchar(20) Declare @PrefixLen varchar(20) Declare @AfterPrefixLen varchar(20) DECLARE Cur_Prefix CUR...

Query problem

When I execute this query: Dim Var Var = ("select max(Autonumber) from tblAutonumber") DoCmd.RunSQL (Var) I am getting the value of var as "select max(Autonumber) from tblAutonumber" instead of the maximum value I am looking for. Code: Private Sub btnSubmit_Enter() DoCmd.RunSQL ("insert into tblAutonumber (Dummy)values ('DummyValue'...

#define Equivalent for Oracle SQL?

Is there a SQL equivalent to #define? I am using NUMBER(7) for ID's in my DB and I'd like to do something like: #define ID NUMBER(7) Then I could use ID in the creation of my tables: CREATE table Person ( PersonID ID, Name VARCHAR2(31) ) This will allow me to easily change the type of all of my IDs if I realize I need more...

Accessing SQL Database in Excel-VBA

I am copying an VBA code snippet from MSDN that shows me how to grab results from a SQL query into excel sheet (Excel 2007): Sub GetDataFromADO() 'Declare variables' Set objMyConn = New ADODB.Connection Set objMyCmd = New ADODB.Command Set objMyRecordset = New ADODB.Recordset 'Open Connection' o...

Is there an Oracle SQL query that aggregates multiple rows into one row?

I have a table that looks like this: A 1 A 2 B 1 B 2 And I want to produce a result set that looks like this: A 1 2 B 1 2 Is there a SQL statement that will do this? I am using Oracle. Related questions: Returning multiple rows from a single row My question is close to the opposite of this question. Use LINQ to concatenate...

Is the BULK INSERT command asynchronous when issues from .Net?

I have a bulk insert command that I am issuing through C#. Is the command asynchronous. Also is it possible for the command to return before its released the file lock on the file being inserted. ...

sql server count of max values without subquery

I want to write a T-SQL query which returns not only the maximum value, but the number of rows having the maximum value. There must be a better way than what I have come up with --wrong way select LibraryBranchId, max(daysCheckedOut), count(daysCheckedOut) from books group by LibraryBranchId LibraryBranchId Expr1 Expr2 -...

Easy way to write a string with control characters to an nvarchar field in a DB?

EDIT: Accepted answer points out what my issue was. I added another answer which shows an even easier way. I have a multiline textbox from which I create a single string: Dim wholeThing As String Dim line as String For Each line In txtMultiline.Lines wholeThing = wholeThing & line & Environment.Newline Next ...

SQL nvarchar Performance

I'm storing localized strings in a single datatable using MS Sql (2008 or whatever). Most of the strings are short and can be represented with varchar(200), while about 10% are much longer require something like varchar(5000). My question is, is there a performance advantage when retrieving shorter strings if I break this into two tables...

Generate CREATE scripts for a list of indexes

Hi all! As part of a collation changing exercise, I have a list of indexes (122) that needs to be dropped and then re-created. How can I re-create these indexes without having to go through the GUI and scripting it to a query window each time? My list of indexes is obtained from this script WITH indexCTE AS ( SELECT Table_Nam...

Determining Formula Field

Hi all, Guys, I am using SQL Server 2000 and executing the sp_columns stored procedure to get a layout of my table. One of my fields is a formula field and my question is, how can I determine this through sp_columns? sp_columns does not seem to show this information. THanks in advance ...

Django and SQL question: Reduce number of database hits

Hello, For one of my clients, I am generating a clients list from the Django Admin. It splits the clients by status: current, acquired, and past. Currently, the view code for that list is as follows: def clients_list(request): current_clients = Client.objects.all().filter(status='current')[:10] acquired_clients = Client.objects.all()....

Get last log line per unique host from table

Hi, I have inherited an application that logs the results of certain daily commands that run on multiple hosts to an MS-SQL table. Now I've been asked to provide a view/query that displays the last log line per host to get an overview of the last results. The table is similar to this: ------------------------------ |HOST |LAST_RUN ...

Help me with this SQL: 'DO THIS for ALL ROWS in TABLE'

[using SQL Server 2005] I have a table full of users, I want to assign every single user in the table (16,000+) to a course by creating a new entry in the assignment table as well as a new entry in the course tracking table so their data can be tracked. The problem is I do no know how to do a loop in SQL because I don't think you can bu...

Select percentage of rows with different values

On a website I run, I let users rate the individual posts (3, 2, 1). I use the following SQL (in MySQL) to get the percentage of votes of each value: SELECT vote, COUNT(*) * t.factor AS pct FROM ratings JOIN ( SELECT 100 / COUNT(*) AS factor FROM ratings ) AS t GROUP BY vote LIMIT 0, 30; That works fine for calculating the per...