sql-server

How I can use a function which returns a table in a select statement with an inner join?

I need to use a function which returns a table, in a inner join sentence passing a parameter. When executed, the sentence like this is not working. SELECT T0.Code,T0.Data1,T0,Data2 FROM [dbo].[FNGet_Data] (T1.Code,'2010-01','USD') T0 INNER JOIN Codes T1 ON T1.Code=T0.Code When executed the sentence using a constant parameter works...

Why must QUOTED_IDENTIFIER be on for the whole db if you have an indexed view?

Yesterday I added some indexes on a view in my MSSQL 2008 db. After that it seems like all the store procedures need to run with QUOTED_IDENTIFIER set to ON, even those that don't use the view in question. Why is it so? Is this something I can configure on the db or do I have to update all my stored procedures to set the QUOTED_IDENTIFI...

Help with SQL Server query

I have table that contain name and date. I need to count how many names I have in a one day, and make average to all days. How to do it? Thanks in advance ...

How can I use single query to insert multiple records from Dataset into SQL Server 2005 ?

I have a dataset in ADO.NET containing multiple records from user side. I need to insert all those rows in single query into the database, in order to avoid multiple queries ...

Is NOLOCK the default for SELECT statements in SQL Server 2005?

I have only SQL Server 2008R2 installed though I need to communicate with customers having 2005. [1] tells: "NOLOCK This does not lock any object. This is the default for SELECT operations. It does not apply to INSERT, UPDATE, and DELETE statements" [2] doesn't seem to mention it, but my checking in SSMS/SS 2008R2 shows that n...

I can't add Microsoft.SqlServer.Management.Common to my ASP.NET MVC Application

I am trying to add a reference to the above assembly but it does not appear in my ASP.NET MVC .NET 4 (Not client) applications Assembly list. Does anyone know how to reference this Assembly? ...

Adding a new primary key to existing table

I have table with following details Table name EMPLOYEE and columns EMPID (PK smallint not null) EMPNAME (varchar 256 not null) ORG (FK smallint not null) FUNCTION (FK smallint not null) EFF_DATE (datetime null) AUDIT_ID (varchar null) Now I have to add an extra coulmn to this table ADD_UID and make it also primary key I am using th...

String concatenation issue in CTE SQL

I have the following CTE SQL WITH Tasks AS ( SELECT TaskID, ParentTaskID, CAST(SortKey AS nChar) AS sort_key /*,cast(SortKey as char) as sort_key */ FROM oaTasks AS s WHERE (TaskID = 1) UNION ALL SELECT s2.TaskID, s2.ParentTaskID ,Cast( '0.'+ cast(Tasks_2.sort_key as...

how to create a table from an excel sheet?

Is there an easy tutorial? I'd like to create a table that exactly matches the excel table, is it possible to do something like "create table from excel sheet"? ...

SQL Server 2005 Linked Server Query Does Not Return Expected Error

I am querying a linked SQL Server and not getting an error that I do get when querying locally. Something like this: SELECT CAST(ColumnName AS INT) FROM TableName and this: SELECT CAST(ColumnName AS INT) FROM ServerName.DatabaseName.Schema.TableName The first query when run locally returns an error 'Arithmetic overflow error convert...

MSSQL: LENGTH() inside of REPLICATE()

Hello everyone I have a MSSQL table with the columns "Lvl" and "Title". I need to insert a "-" in front of the title for every character in the Lvl field. As an example: If Lvl = 111 the title shoud become "--- My Title". I can only edit the following SQL-String. There is no possibility to create other functions or likewise. SELECT ...

Where can I find TableDiff.exe?

I just found out about the TableDiff tool for SQL Server on the hidden features question and had a full-blown nerdgasm. I would like to download the tool, but everywhere I look I am told to look in C:\Program Files\Microsoft SQL Server\90\COM\TableDiff.exe. After looking everywhere on my PC (I have SQL Server 2008 Express and SQL Server ...

SQL Server Pivot Table Help

I'm trying to turn the following ResultSet Meetings Covers Date TypeName 1 3 2010-10-14 Breakfast 1 1 2010-10-14 LunchCooked 2 4 2010-10-15 Breakfast 1 3 2010-10-18 Breakfast 1 3 2010-10-19 Breakfast 1 1 2010-10-19 LunchSandwich 1 ...

Versoning in relational database

Hallo all, I have a problem to introduce a good versioning in my database design. Let's make a easy example. A little rental service. You have a table Person (P_ID, Name), table Computer (C_ID, Type) and a table Rent (R_ID, P_ID, C_ID, FromData, ToData). I want to be able to change say the user name, create a new version and still ha...

Get SQL Insert to work when PK is supplied or NOT.

Hi All I have the following stored procedure: ALTER Procedure dbo.APPL_ServerEnvironmentInsert ( @ServerEnvironmentName varchar(50), @ServerEnvironmentDescription varchar(1000), @UserCreatedId uniqueidentifier, @ServerEnvironmentId uniqueidentifier OUTPUT ) WITH RECOMPILE AS -- Stores the ServerEnvironmentId. DE...

FULLTEXT search with a multi-language column

Is there a way to use FULLTEXT in a multi-language table without giving each language its own column? I have one column I need to search, but the language in that column varies: ProductID int Description nvarchar(max) Language char(2) Language can be one of: en, de, it, kr, th Currently I build a concordance and use that for...

How to know MS SQL Server Database version? 2005 or 2008, for example?

Hi. I want to know the version of an "mdf" MS SQL Server database file. I have the "SQL Server Management Studio" tool for help if it's needed. in the "Properties" of the mdf file, I've found: "Version -> 10.xxx" Regards..... ...

Storing unknown datatype in MS SQL Server Database

Hi, Does any one has an idea of whats the best practice to store an unknown data type in a table. Basically I would need to store types like bit, smallint, int, real and nvarchar in the same "value" column, for later interpretation by a .NET application. I was trying to achieve the best possible solution not to compromise the performan...

I cant reach my new SQL instance

I was using a older version of SQL on my server, and it worked fine when only typing the servername,, I could directly connect to the server, I recently installed a new instance of SQL, and Iam trying to connect to the new instance but it dowsne't work. SERVERNAME/New_instance CAn someone help me out? How can I reach the new SQL se...

SQL Server char(1) and char(2) column

I need a table for bookkeeping all types in the data model. I don't have that many types but a fair deal of 'em. Ideally short descripive names would work well. So I did this: CREATE TABLE EntityType ( EntityTypeID char(2) PRIMARY KEY, EntityTypeName varchar(128) NOT NULL ) And put some data into the table: INSERT INTO Entit...