sql-server

Shema binding for a UDF using tables from other db

I have a UDF in SQL 2005 that I would need to schemabind as it is used in a view that I need an index on. This UDF gets information from a table that is located in a different db (same server) then the one where the UDF is located. Since it is invalid to specify table as [DBName].dbo.[Tablename], is there a way I can get the info from ...

SQL Pivot Table

I have a SQL view with following data: ID ClassName Description Flags 1 Class1 Desc1 F1 2 Class1 Desc1 F2 3 Class1 Desc1 F3 4 Class1 Desc1 F4 5 Class2 Desc2 F2 6 Class2 Desc2 F6 7 Class3 Desc3 F1 8 Clas...

Requested operation requires an OLE DB Session object... - Connecting Excel to SQL server via ADO

I'm attempting to take Excel 2003 and connect it to SQL Server 2000 to run a few dynamicly generated SQL Queries which ultimately filling certain cells. I'm attempting to do this via VBA via ADO (I've tried 2.8 to 2.0) but I'm getting an error while setting the ActiveConnection variable which is inside the ADODB.Connection object. I ne...

SQL Table Design - Identity Columns

SQL Server 2008 Database Question. I have 2 tables, for arguments sake called Customers and Users where a single Customer can have 1 to n Users. The Customers table generates a CustomerId which is a seeded identity with a +1 increment on it. What I'm after in the Users table is a compound key comprising the CustomerId and a sequence nu...

Set-theory way of determining a time difference between a "group" of records via SQL.

I have a log file in SqlServer that stores the time an application started, the time the application is ready (i.e. finished loading), and the time that it's exited. Each of these occur as a separate entry. The format (and sample data) is as follows: Date/Time User Type Application Message 2009-11-03 12:26:12.403...

SQL Server Database Design Problem/Challenge

I have a database that has node & nodetype tables. Nodes table NodeID ParentNodeID NodeTypeID NodeName ... NodeType Table NodeTypeID ParentNodeTypeID NodeTypeName ..... Both tables have a relationship to itself. There are different types of node i.e Node Site Building Office These are hierarchical, so information (attributes) th...

How may I change the default TRANSACTION ISOLATION LEVEL in SQL Server 2005?

Hello All, I know the default TRANSACTION ISOLATION LEVEL in SQL Server is "read committed". If I want to change it to "READ UNCOMMITTED", how may i make this configuration change? note: I cannot use SET GLOBAL TRANSACTION ISOLATION LEVEL, which only apply in the current session. I cannot add NOLOCK in the queries because there are ...

stored proc return all rows when parameters are null

when the optional parameters are null or empty how can i ignore that condition? e.g. declare @color nvarchar(50) declare @time datetime set @color = null select * from apples where apple.color = @color and apple.time = @time if @color or @time is null , i would like to ignore that condition. ...

Passing foreign language characters to/from a database

I am trying to allow users to enter Hebrew characters into certain fields in an HTML form (processed using java). I did some research, and it is apparent that the following tag needs to be part of the HTML document: <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> That being done, I am having the following result...

Can’t restore SQL Server 2000 backup to SQL Server 2008

I have a backup file taken from a SQL Server 2000 database and I'm trying to restore it to a 2008 database. However, I'm getting this error: An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo) The media family on device 'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\M...

if else condition for update a table in a storeprocedure in sqlserver2005

I want to update some data in a specified case, else these fields are not to be updated. What can i write code in a stored procedure for this? ...

DB file size from master..sysaltfiles

I'm trying to retrieve db sizes of all databases in my SQL Server 2005 instance. I found this select filename, size, 8192.0E * size / 1048576.0E as result from master..sysaltfiles Is the result varibale in KB? How can get this to MB? I'm confused. ...

code for update

My table name is table_1, fields are: name dept location status Status is already 1, but I want to update the status into 2 based on a certain condition else not update. My code is UPDATE Table_1 SET model = @model, make = @make, [Asset Serial No / Service Tag] = @Asset, [IT Asset Tag] = @AssetTag, ...

SQL Server: How to extract comments from stored procedures for deployment

We have lots of stored procedures which all contain a lot of comments. Is there a way to extract the comments from the stored procedures for deployment so the users can't see them when they modify a stored procedure with SQL Server Management Studio? Note: We're using SQL Server 2008. ...

Using NHibernate with ancient database with some "dynamic" tables

I have a legacy database with a pretty evil design that I need to write some applications for. I am not allowed to touch the database design at all, seeing how this is a fragile old system held together by spit and prayers. I am of course very aware that this is not how the database should have been designed in the first place, but real ...

SQL SERVER OBJECT_ID

i want to execute the query in master database it self IF OBJECT_ID(N'DB1.dbo.T_table1', N'U') IS NOT NULL AND COLUMNPROPERTY(OBJECT_ID(N'db1.dbo.T_table1'), 'KEY_value','AllowsNull') IS NOT NULL SELECT 'TRUE' AS COLUMNSTATUS ELSE SELECT 'FALSE' AS COLUMNSTATUS but its not working? give me suggestion. ...

sql server bulk insert

i want to insert csv file with special character how can csv file to sql server database with special character ...

SQL Compact import DB from SQL Server Express with Server Management Studio

Hi! I try to import sql script, generated with Server Management Studio, into SQL Compact 3.5 and get a lot of error. What I am doing wrong? I generate script with "Task/Generate Script" context menu. Part of my script: CREATE TABLE [LogMagazines]( [IdUser] [int] NOT NULL, [Text] [nvarchar](500) NULL, [TypeLog] [int] NOT NULL, [Date...

MDX performance vs. T-SQL

I have a database containing tables with more than 600 million records and a set of stored procedures that make complex search operations on the database. The performance of the stored procedures is so slow even with suitable indexes on the tables. The design of the database is a normal relational db design. I want to change the database...

Database design question. BIT column for deletions

Hi guys, Part of my table design is to include a IsDeleted BIT column that is set to 1 whenever a user deletes a record. Therefore all SELECTS are inevitable accompanied by a WHERE IsDeleted = 0 condition. I read in a previous question (I cannot for the love of God re-find that post and reference it) that this might not be the best des...