sql-server-2005

SQL Server 2005 SQL Authentication Connection String

Hello, I'm building an application that connects to SQL Server 2005. It currently uses Windows authentication, but I'd like to switch to SQL Authentication (I believe it is also sometimes called Mixed Authentication). My current connection string is: "Data Source=LOCALHOST;Initial Catalog={0};Integrated Security=SSPI" That's for Windo...

how to update value from another TSQL

I have to update value based on values from another table: update OracleOb..NS.myTable set name = (select name from myTable1 where id = 1) where id = 1 here the SQL has some problem. How can I get value from myTable1 and set it to myTable? I am using MS SQL 2005. Sorry I have to edit this question again. The table myTable is a li...

Remove the last character in a string in T-SQL?

How do I remove the last character in a string in T-SQL? I.E. 'TEST STRING' to return: 'TEST STRIN' thanks Dave ...

sql max/min query and data transformation

update: changed one time to show that the times per shipment may not be in sequential order always. here is my input create table test ( shipment_id int, stop_seq tinyint, time datetime ) insert into test values (1,1,'2009-8-10 8:00:00') insert into test values (1,2,'2009-8-10 9:00:00') insert into test values (1,3,'2009-8-10 10:00...

Convert values stored in XML into ntext and date types in SQL Server 2005

I'm working on a stored procedure for a calendar application. Each event in the calendar can have several dates. This information is stored in two different tables. Rather than write two stored procedures and call the second one multiple times to save the dates, I'd rather just pass them in using XML. The trouble is that I want to conver...

SQL Sub-query -- Select JobID with a maximum JobValue

This seems like an easy thing, but I'm drawing a blank. Select * from .... inner join ( select JobsID, Value from Jobs where Value **is the highest** ) as MaxJob on MaxJob.CustID = A.CustID inner join ( select other information based upon MaxJob.JobID ) as OtherStuff Is there a nice way to have that first subquery gi...

SQL Server 2005 Syntax Help - "Select Info based upon Max Value of Sub Query"

The objective is below the list of tables. Tables: Table: Job JobID CustomerID Value Year Table: Customer CustomerID CustName Table: Invoice SaleAmount CustomerID The Objective Part 1: (easy) I need to select all invoice records and sort by Customer (To place nice w/ Crystal Reports) Select * from Invoice as A inner join...

What is the difference between SET xact_abort ON and try/catch block with Transaction handling in sqlserver 2005?

Hi all, I need to improve some existing stored procedures in my project for better transaction handling. I understand I can use the SET XACT_Abort ON statement in my procedure so that transaction will be automatically rolled back in case of errors. I can also use Try/Catch block for error handling and roll back the transaction in the Cat...

Get list of parent and child records with multiple entries with criteria - SQL 2005

Hi, I have parent / child tables: parent table: id | description 1 | Alexandra 2 | Natalia child table: id | id_parent | description 1 | 1 | Programmer 2 | 1 | Surgery 3 | 2 | Programmer 4 | 2 | IT How to return set of record according filters, like if we want to get all records with "Programm...

Huge Errorlog with SQL Server 2005 Express (15GB)

With SQL Server 2005 Express (obeserved on XP and Server 2003), I get sometimes huge Error logs files in production: The file C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\LOG\ERRORLOG grows to fill the disk (file size becomes more than 15 GB). This file is not the transaction log, just the error log : a text log for SQL Server. ...

Insert using single insert statement.

Hi, I want to insert the data in my table tblSubscriptions and I only want to use one insert statement. I am going to insert data for every userId in User Table. The following SQL doesnot work. Insert tblSubscriptions (UserID, ProductID, isACtive, SubscriptionDays, Price, MonthlyPrice, ProductType, CurrencyID) Values ((Select userID Fr...

How to set morethan max size charecters in NVARCHAR(MAX),sql Server2005

Hi All, I am using declare @insertsql nvarchar(MAX) --above @insertsql for sp_executesql takes only nvarchar as input set @insertsql='--i am giving More than 10000 characters here -----' EXEC sp_executesql @insertsql, N'@inXMLRequest XML OUTPUT', @inXMLRequest OUTPUT how to insert morethan 10000 charecters in NVARCHAR(MAX) in sq...

How to set morethan max size charecters in NVARCHAR(MAX),sql Server2005

Hi All, I am using declare @insertsql nvarchar(MAX) --above @insertsql for sp_executesql takes only nvarchar as input set @insertsql='--i am giving More than 10000 characters here -----' EXEC sp_executesql @insertsql, N'@inXMLRequest XML OUTPUT', @inXMLRequest OUTPUT how to insert morethan 10000 charecters in NVARCHAR(MAX) in sql...

Best way to use a Scalar UDF that needs to appear in the Select and Where clauses

I have an expensive scalar UDF that I need to include in a select statement and use that value to narrow the results in the where clause. The UDF takes parameters from the current row so I can't just store it in a var and select from that. Running the UDF twice per row just feels wrong: Select someField, someOtherField, ...

SQL Server 2005 SP Deadlock issue

I have a scheduled job with a SP running on daily basis (SQL Server 2005). Recently I frequently encounter deadlock problem for this SP. Here is the error message: Message Executed as user: dbo. Transaction (Process ID 56) was deadlocked on thread | communication buffer resources with another process and has been chosen as the deadlock...

SQL Server: How to create a temp table with unkown columns dataype/names?

I need to make a query on multiple databases. I got the part for building the query for every database but now i need to put the result in something for each query then i can return it. @requete is a query ALTER PROCEDURE [dbo].[RequeteMultiBd] @requete varchar(max) AS BEGIN --get server + database name select dbo.trim(Ser...

Having to rebuild indexes twice on a table

I have a table in a SQL 2005 database which is brand new. As part of our application deployment we load the table with about 2.6M rows. Once that is done, the indexes on the table are all rebuilt. Then the users are let into the system and queries against that table time out. I can then rebuild the indexes (using the same exact script th...

[SSRS 2005] The data set name is missing in the data region 'DataSetName'

I added an additional, new DataSet to my report and have been getting this cryptic error ever since. ...

Three table join with joins other than INNER JOIN

I am learning SQL and am trying to learn JOINs this week. I have gotten to the level where I can do three table joins, similar to a lot of examples I've seen. I'm still trying to figure out the tiny details of how things work. All the examples I've seen of three table joins use INNER JOINS only. What about LEFT and RIGHT JOINs? Do ...

What is wrong with the code below

CREATE FUNCTION GetPayCodeList ( -- Add the parameters for the function here @PC varchar(50) ) RETURNS TABLE AS RETURN ( IF @PC = '*' SELECT DISTINCT ID, Code, Description FROM tbl ELSE SELECT DISTINCT ID, Code, Description FROM t...