Tag: sql-server-2005

how to select table name from the table itself in a dynamic way?

I want to select table name from the table itself for example Select * ,(TableName) from Table1 union Select *,(TableName) from Table2 i don’t want to do it in a static way Select * ,’TableName’ as tbl from Table1 union Select *,’TableName’ as tbl from Table2 thanks in advance

Grouping Query Help in SQL Server

I am trying to sort my data by certain groups of people. My Data Looks Like: Origional_Date ID FORM Total 2012-03-01 1855 3 1283 2012-03-01 2869 4 2306 2012-03-01 5555 4 6440 2012-03-01 5555 3 8373 2012-03-01 2527 3 8476 2012-03-01 922 3 823 2012-03-15 2907 4 1420 2012-03-15 5555 3 2892 2012-03-15 2914 4 […]

Returning multiple values in a CASE expression

I have an outdated stored procedure that looks something like: CASE WHEN (org.org_misc_data = ‘PAC’) THEN ‘pac’ WHEN (org.dues_category = ‘PART’) THEN ‘partner_member’ WHEN (org.dues_category = ‘FREE’ AND org.org_status_flag = ‘P’) THEN ‘associate_member’ ELSE ‘non_member’ END AS org_status The way it it currently written, as soon as it hits the first WHEN clause, my org_status […]

How to add the primary key and I have increment the record 1 by 1

I have to add a auto_Increment primary key column to the table. I used this script to create but its doing fine. but one thing is thtat I have alredy have a primary key in that table. so its throwing an error. how to remove alredy existing primary and making a new auto_increamtn column has […]

Turning off consistency check on Microsoft SQL script restore

On several other databases I’ve come across, one can turn off the consistency check when restoring a (scripted) dump of the database. The idea is that when you have dumped the script from a database, you can restore it safely, without doing consistency checks, both to speed things up, and to not be hindered by […]

SQL Server how can I get the code of a foreign key constraint

I can get the code of a stored procedure using the syscomments table. select so.name, sc.text as storedproccode from sysobjects so (nolock) inner join syscomments sc (nolock) on sc.id = so.id where so.name = ‘tablename’ How can I get the code for a specific foreign key constraint? I have the foreign key name. Let me […]

SQL Server Multitable Select with IF-Else

I have the following sql which returns Projects and related Contractors as well as document size info from three different tables. The sequence is: First Contractors are entered in the system, then Projects are entered for each Contractors, during with document sizes (sheets) are entered. So far so good: The following sql returns all projects […]

How can I run the mssql functions in php?

I’m getting this annoying message: Fatal error: Call to undefined function mssql_connect() I’ve read many threads where they say just uncomment the php_mssql.dll, but there is no such file in my extension folder and neither is it listed in php.ini. And I can’t seem to find it anywhere. All the links posted on forums are […]

Row handle referred to a deleted row or a row marked for deletion

We have an old site that is giving us an error. It uses VBScript and the DB is SQL Server 2005. Here is the code: set oNotes = server.CreateObject(“SCRIPTING.DICTIONARY”) openSQL “SELECT * FROM v_client_notes WHERE contact_id = ” &_ my_contactID & ” ORDER BY client_notes_duedate ASC” do while rs.eof = false set temp = server.CreateObject(“SCRIPTING.DICTIONARY”) […]

SQL Server CLR TVF to return two new columns into dataflow

With regards to this question here SQL CLR return two new columns I am trying to create a simple SQL CLR function, where I can pass two strings into the function and it passes me back two NEW columns. So say I have the following data:- Col A Col B Bob Joe Jane John I […]

MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.