sql-server

pivot table row to column

Hi Everyone, I'm using SQLServer2008 Express I have a table and a script to convert the rows into columns with expected result as PARENT_ID name01 name02 name03 name04 1 ABC DEF ABC2 DEF2 2 DEF3 null null null However, I get the result as PARENT_ID name01 name02 name03 ...

Linked Informix table in MS SQL Server ignoring criteria?

I’m having a problem with a linked Informix table in MS SQL Server 2008r2. When I query this table, it seems to ignore some of the criteria I’m passing to it but not others. For example if I put a condition on the rowdate field the remote query part of the execution plan does not show any WHERE clause but if I put criteria on another fie...

SQL Server adding one month to a date represented as an 8 digit decimal

A SQL Server application we use (accpac) represents dates as an 8 digit decimal in ISO format (example: today's date is 20100802) I need to add one month to this. I've found a way to do it, but there must be a better way. The steps of my solution are: declare @accpacDate as decimal set @accpacDate = 20100101 declare @date1 as date dec...

SQL Stored Procedure not returning any data

When I run a simple SELECT statement on this table I get a row back (this is correct there should only be one). Here is that SELECT statement: select * from Lending.HMDA where BatchId = 1 Here is the proc I am executing, which returns no rows: DECLARE @BatchStartDate datetime, @BatchEndDate datetime SELECT @BatchStartDate = ...

Automatically Setting a Field Value in SQL

Hello, I have a SQL Server 2008 database with two tables. The first table is called Department. The second table is called Ticket. These two tables are defined as follows: Department ---------- ID Name TotalTickets Ticket ------ ID DepartmentID Description AssignedTo I'm trying to figure out a way to dynamically update the Departmen...

problem with sql table updation

I have 2 tables CREATE TABLE PODRAS_MS.tbl_FieldWorkers ( [FWInsOnServerID] INT NOT NULL IDENTITY(1,1), [BaseStationID] INT NOT NULL, [RefID] INT NOT NULL, [DisSubInsID] INT NOT NULL, [FieldWorkerID] CHAR(7) NOT NULL, ...

how to restore a sql server backup containing filestream data assigning a new folder name for filestream data?

To create a new database and populate it from a backup I typically do: CREATE DATABASE MyDatabase -- I create an empty database -- I retrieve the filepath of mdf and ldf files DECLARE @FileData varchar(1000) DECLARE @FileLog varchar(1000) set @FileData = (select filename from MyDatabase.dbo.sysfiles where fileid = 1) set @FileLog = (s...

Catch an exception of an asynchronous called SQL-Server stored procedure

I call asynchrounously some stored procedures with BeginExecuteNonQuery and EndExecuteNonQuery (in C#). How can I catch the (defined) exceptions of these stored procedures in the C# program? Or does the try{}catch{} also works for asynchrounous calls? ...

N-Tier with C# ?

I am looking at writing a WinForms app and getting stumped over what seems to be simple issue. There is a server and database (SQL Server) Open ports are HTTP, HTTPS There is a WinForms client. It needs to connect a TCP/IP stream (possibly HTTP, SOAP, REST) to the server. Sometimes the WinForms client goes off-line and then the WinFor...

How Can I Sum Vat in a column in sql server 2008?

Hi all suppose i have the following table CREATE TABLE #ResultTable (NettAmount money, GrossAmount money,TotalVat money) Given a gross amount eg=250 I know that vat is at 17.5% How Do i calculate the totalVat? Thanks for any suggestions ...

Creating an Update Trigger

Hello, I have SQL Server 2008 database with two tables. The first table is called Shelf. The second table is called Product. Each Product will belong to a Shelf. Based on this, I have a table structure that looks like: **Product** ID (int) ShelfID (int) Description (text) **Shelf** ID (int) AisleNumber (int) TotalProducts (int) When...

NHibernate inner Join an Oracle and Sql Server Database

I am building an object from multiple datasources. Does anyone know whether this is possible in NHibernate and how. I should mention that one source is SQL the other ORACLE. ...

SQL Server Enable Active Directory User

I work at a college a change to policy is Students windows accounts are now disabled upon creation and are only enabled upon them passing a test. Don't ask So I can easily modify my DSADD with -disabled yes However I need to enable them when they pass the test. I obtain the test results from a sql server so is it possible to enable the...

Allow Ad Hoc Distribution Queries for all users

Hi, I am using AD Hoc Distribution Queries to transfer Data from MS SQLServer 2008 to MS Access. The process is started using a single SQL Statement: INSERT INTO OpenDataSource('Microsoft.Jet.OLEDB.4.0', 'Data Source=C:\temp\target.mdb;User ID=Admin;Password=;')...testtable select * from dbo.testtable To do that I have set the Ad H...

SSRS - Group_Concat Equivalent using an Expression?

Can I use expressions in Sql Server Reporting services to combine all of the values of a column within a group? I'm trying to accomplish what MySQL's group_concat function does, but in the report (not in the query). Example. I want to make this data: Group 1 Value Test A B Test 2 C D Look this t...

sql server table contains special foreign characters

I realized after populating the table that it contains special encoding for foreign characters. I changed it to nvarchar but how do update the records already in the table since I still see it in the table. for example Börsenblatt ...

SQL Server Full Text Search Index View

I want to use the Full Text Search feature of Microsoft SQL Server. If I have a table Client which refers other tables like City, Country, Department, etc. is it better to create a separate table that would hold de-normalized data, which would then be full text indexed, or is it better to create a dummy value in every foreign table (for...

Moving from 32-bit to 64-bit machine, how to make linked server work

Here is some sample code: DECLARE @sourceFile varchar(255), @testRows int SELECT @sourceFile = @xmlInfo.value('(/SelectFile/DataSource)[1]', 'VARCHAR(255)') EXEC sp_addlinkedserver 'SomeData', 'Excel', 'Microsoft.Jet.OLEDB.4.0', @sourceFile, '', 'Excel 8.0', '' IF @xmlInfo.exist('/ConfigArgs/ParamsXml/ImportDealerData') = 1 ...

SQL Server syntax error when using OPENROWSET?

I'm trying to write this as part of stored procedure on SQL Server 2000. I keep getting a syntax error thrown on line starting Insert into OPENROWSET(..... Help! I can't see the syntax error! DECLARE @vDate Varchar(25) DECLARE @vCommand nvarchar(1000) DECLARE @fileName varchar(500) SET @vDate = LEFT(DATENAME(month, DATEADD(m, -...

Moving from 32-bit to 64-bit, how to make linked server (sp_addlinkedserver) work

Here is some sample code that worked fine in a 32-bit machine (SQL server 2005) and needs to be updated for a 64-bit... I know this is a common problem but have not been able to find how to fix it! DECLARE @sourceFile varchar(255), @testRows int SELECT @sourceFile = @xmlInfo.value('(/SelectFile/DataSource)[1]', 'VARCHAR(100)') ...