sql-server

CakePHP: error when trying to use mssql datasource

Hi, This is my first time using ms sql with cakephp. Usually I use mysql. I've edited my database.php file: class DATABASE_CONFIG { var $default = array( 'driver' => 'mssql', 'persistent' => false, 'host' => 'jura', 'login' => 'sa', 'password' => '********', 'database' => 'clientportal', 'prefix' => '', ); ...

How do I retrieve data from SQL server table which has two columns say PatientID and TestNo, Differnt TestNo can have same patient ID

I have a database (SQL server 2005 Express) table wth columns PatientID (more than 1 records can have same patient ID) and TestNo. I want to retrieve the maximum of testNo column among all the records with same PatientID.What should be the SQL statement to do so?I am using RecordSet pointer to access the records in a vc++ application. ...

Sql server To use nvarchar or bigint

This might be a stupid question. I need to have a Id field in a table. This Id is not a key (primary or whatever). The requirement says that user can input 10 digits in this field from the UI. This Id has no relation as of now with any otehr object in the system. Do you think If one can use nvarchar or bigint for this field. Does bigint ...

How to take backup of database in SQL server on network location through a job?

Hi All, I need to take the backup of database in SQL server on network location through creating a job in SQL server 2005. can anyone know how to do it? ...

How to prefix 'N' for the parameters in a store procedure for a unicode strings

How to prefix 'N' for the parameters in a store procedure for a unicode strings in c#, alternatively i am using the same procedure for the non unicode also. i need to append it only for the unicode ones kindly help. ...

SQL field = other field minus an other ROW!

Table has 2 cols: [nr] and [diff] diff is empty (so far - need to fill) nr has numbers: 1 2 45 677 43523452 on the diff column i need to add the differences between pairs 1 | 0 2 | 1 45 | 43 677 | 632 43523452 | 43522775 so basically something like : update tbl set diff = @nr - @nrold where nr = @nr but i don't want...

Generate sql server scripts using .net framework

Hi all, it is possible to generate script from sql server using .net framework. Example if I have database "Northwind". Then I wish to create/generate script insert" in form file extension .sql (ex: northwind_insert.sql). Is something like when you using sql-server "right-click on table" > "script table as" > "Insert to" > "file". I w...

HOWTO get distinct characters of string column in mssql

hy there! given: | name -+--------------------------- | Josef Knoller | Josef Somos | KFZ Wiesauer wanted result: JOSEFKNMLRZWIAU (case in the result does not matter - it was just easier holding the UPPER key while writing) is there any way to do this in mssql? thanks in advance! EDIT sorry ... i've mixed column and row ......

Is is possible to get new values for Id (IDENTITY) before inserting data in a table ?

Is is possible to get new values for Id (IDENTITY) before inserting data in a table ? Is is possible to write something like that : INSERT INTO Table1 SELECT *GET_NEW_IDENTITY*, Field1, Field2 FROM Table2 I need the values of Id because I want to insert data in Table1 and, just after, insert data in another table which has a foreign ...

Weird error when trying to add a stored procedure to PVCS

I'm trying to add an SQL stored procedure to our PVCS directory, and I'm seeing a weird error pop up. First, I get a dialog box containing ÿþC. When I click OK on this dialog box, I'm told that - An error has ocurred: The stored procedure code does not use the CREATE method. Please check your syntax. Despite the fact that my...

procedure to upload excel into sql server

Hallo All, Please help in determining the best procedure for the following problem. In a user interface, there is a provision to upload excel file. This is done by admin, once/twice in a day on a regular basis. The code that i have used to upload excel file into sql server. select * into #temp FROM OPENROWSET('Microsoft.Jet.OLEDB.4....

SQL Server - Drop and Recreate a Table - Blocking Access While Doing So

Hi, I need to drop and recreate a table, which exists to "cache" an expensive view. The view may change and I want to make maintenance as easy as possible, so I want the new table to reflect the latest version of the view. I also want to be able to prevent read errors should a procedure try to access the table while it is in the middl...

Selecting a set of distinct values and counting them individually into new columns

I'm fairly sure this is an easy thing to do, but I'm a newbie at SQL so be gentle. If I want to write a query, that adds up the total occurences of each process number and stores those values to a new column, what do I do? I thought some mixture of count(distinct ...) could get it down but I'm not sure. See the result table for what I'm ...

SQL Server: Why does comparison null=value return true for NOT IN?

Why does the comparison of value to null return false, except when using a NOT IN, where it returns true? Given a query to find all stackoverflow users who have a post: SELECT * FROM Users WHERE UserID IN (SELECT UserID FROM Posts) This works as expected; i get a list of all users who have a post. Now query for the inverse; find a...

SQL CTE and ORDER BY affecting result set

I've pasted a very simplified version of my SQL query below. The problem that I'm running into is that the ORDER BY statement is affecting the select results of my CTE. I haven't been able to understand why this is, my original thinking was that within the CTE, I execute some SELECT statement, then the ORDER BY should work on THOSE resul...

How to determine which databases are being used on SQL Server 2000

I have a SQL Server 2000 box that houses several databases, some of which are probably no longer in use. I'd like to clean things up by first taking them offline, and then later removing them all together. The problem is that I don't know how to tell which of these are still being actively used (outside sources may or may not be connec...

How to tell if SQL Server is local or remote?

In my app the users gets to pick from a list of SQL Server in the network. The thing is I need to know if the chosen instance is a local or remote computer. Is there a way I can ask that SQL instance what computer is she on? Is there a way a can figure that out? Edit1: I want to know the host name where the SQL Server is hosted so I ca...

little help with some tsql

Given following table: rowId AccountId Organization1 Organization2 ----------------------------------------------- 1 1 20 10 2 1 10 20 3 1 40 30 4 2 15 10 5 2 20 15 6 2 10 20 Ho...

Importing images in SQL Server 2005

Dear All, I have another issue. I have in the SQL table Employees. This table has lot of details but I was missing images or photos. So i managed to take all pictures for all employees but I have the pictures in the folder. Each picture is named like an Employee_id which matches the record in the table. How do I import images into SQL ...

How to convert UNIT of MEASURE in SQL SERVER OR ORACLE USING CASE STATEMENT

Hi, Is there a way in SQL SERVER or ORACLE that can use the case statment to convert the Unit of Measure below? select UoM, sum(Quantity) as 'QTY' from mytable group by UoM UoM QTY LBS 2.4 LBS 2 LBS 0.233 LBS 0.97 OZS 1.8 GMS 1236 LBS 120.459 LBS 59.1 LBS 252.82 LBS 175.23 LBS 3.42 LBS 455.4 LBS 57.6 LBS 146.8 LBS 117.78 LBS 197.92 L...