sql-server

Dynamic View name in Table valued function

I'm passing View name as parameter in a Table Valued Function, and I want to fetch some data from that view by building a dynamic SQL and executing it by sp_executesql(). when try to execute the function, I get the error: Only functions and extended stored procedures can be executed from within a function. DBMS: SQL Server 2005 any wor...

Where can i get Remote Blob storage sample database?

Hi, I am working on SQL server 2008 , remote blob storage feature. http://www.codeplex.com/sqlrbs I came across this site. They are mentioning about sample database in this site, can you please suggest where i can get the RBS database. Pls suggest ,Where i can get more information on RBS. Thanks in advance. Sudhakar. ...

My ContainsTable query is not working - please help :)

Hi folks, I've got a full text catalogue setup. It has a unique key count of 117 with 19 items. The table has 19 rows only. The table has an NVARCHAR(50) field called ClientGuid. It's a guid with some weird text at the end. eg.. 8b6ef4a504dd1a57f079180e7f6eb4a0(-) 8b6ef4a504dd1a57f079180e7f6eb4a0(OK) (and no, i didn't defined th...

How to ensure that table was not tampered with in the SQL Server 2008?

I need simple but reliable mechanism to ensure that table was not tampered with in the SQL Server 2008. The assumption is that hacker can access and control only one of the servers (application or database) but cannot access both. Any links or suggestions will be greatly appreciated. Clarification. "Tampering" here means ability to upda...

SQl Full-text search doesn't work?

When i execute the following sql, nothing happens: select * from docs where freetext(*, 'my search string') I know that "my search string" is in a field in a table. The table docs is added to my catalog. The field to search in contains html content. ...

SQL Server Licensing for QA Machines

I'm currently working on some infrastructure costing, and I'm having a bit of trouble finding the best solution for SQL Server licensing for QA servers. We're developing an ETL solution using SSIS. Our solution doesn't have a database per se, but is utilizing SSIS to run validation and transformation on text files in flight. Because we ...

Using SSIS as a datasource for Reporting Services

I have SQL Server 2008 SP1 (64 bit) running SQL Server Integration Services Reporting Services on a Windows 2003 Server (64bit). I'm trying to get Reporting Services to use an integration services package as a datasource. I've created a very simple package that simple reads a text file and loads it into a DataReaderDestination. I ...

Why does casting text as varchar without specifying a length truncate the text at 30 characters?

I was searching an MS-SQL Server 2005 database to make sure that a certain text field was always a multiple of 8 in length. When I ran the following query, I got that several rows were of length 30. But when I investigated those records, I found that they were longer than that. select distinct len(cast(textfield as varchar)) from tabl...

How to choose how to fill #temptable in sql?

Okay, I've got what is probably a very easy question for you Sql gurus out there... Given a boolean of some kind, T, I want to populate a temp table with data set A, if T is true, or data set B, if T is false. I thought this would be how to do it: DECLARE @foo INT SET @foo = null IF (@foo is null) BEGIN SELECT 'foo was nu...

Impact of changing a Unique key in SQL Server 2005

What is the impact of changing a Unique key in SQL Server 2005 I am having a table one primary key ID int and composite unique key for 4 fields. But due to nature of my project one of the keys(fields) of the composite key keeps on changing. Does anyone find any problem in changing the field of composite key that often? ...

Set based calculation for events table, exceptuating an event

Hello, I have a table which contains events for change the state of a maintenance service. This is a sample of data: id date event 234 2009-04-22 10:00:00 Service Request 234 2009-04-22 10:02:00 Service Approbation 234 2009-04-22 10:03:00 Service Asignation 234 2009-04-22 10:40:00 Service Fulfilled ... In a report, i need to show tim...

Getting a Dynamically-Generated Pivot-Table into a Temp Table

I've seen this, so I know how to create a pivot table with a dynamically generated set of fields. My problem now is that I'd like to get the results into a temporary table. I know that in order to get the result set into a temp table from an EXEC statement you need to predefine the temp table. In the case of a dynamically generated piv...

How to set a check on SQL Server?

Hi, I need to add table called group with a column called code How do I add a check constraint to the column so it will only allow the following alphabetic characters (D, M, O, P or T) followed by 2 numeric characters. ...

MSSQL JOIN ON GROUP BY is too slow

I have the following query in MSSQL SELECT TOP 50 CustomerID FROM Ratings WHERE CustomerID != 915 AND MovieID IN (SELECT DISTINCT MovieID FROM Ratings WHERE CustomerID = 915) GROUP BY CustomerID ORDER BY count(*) DESC It is super fast. When I try to use it in a subquery like this. SELECT * FROM Ratings WHERE MovieID = 1 AND CustomerI...

Determine Active Node in SQL Failover Cluster

Does anyone know how to determine the active node of a SQL Active-Passive Failover Cluster programmatically from T-SQL? @@SERVERNAME only returns the virtual server name, which is identical from both nodes. I don't plan to make any decisions based on the data - I trust the failover to do its thing - but I would like to include the info...

Need a better way to manage database schema changes

Currently, we manage database (SQL Server) changes with a series of numbered scripts. One folder holds scripts that can only be run once (table alters, data initialization, etc). Another holds all scripts that can be run multiple times without fear of them destroying anything (stored procedures, functions, etc). Typically, when we need ...

How to enclose square brackets to a variable which has been set as a value of one variable in T-SQL?

I got a script from the Net that computes the usage of datafiles and transaction log files from a certain SQL Server instance. The script works fine if there is not database name with whitespace or is not too long. However, if the database name has whitespace or is too long, I get the error message "Msg 911, Level 16, State 1, Line 1 Cou...

conditionally create user in SQL Server

Hi, I would like to create a user 'foo' in database 'mydb' if the user doesn't already exist. Currently my script looks like this: USE [mydb] CREATE USER [foo] FOR LOGIN [foo] GO However if the user already exists, this fails with an error message: Msg 15023, Level 16, State 1, Line 2 User, group, or role 'jsrvpp' already exists in ...

Connecting to MS SQL Server with JRuby

I'm working on a project that involves some scripting and data storage. The database that I have available to me is MS Sql Server and it is on a windows platform. Despite this I'm looking to leverage Ruby to write the script, specifically JRuby. There are a couple of reasons for this I would like to leverage Prawn to create pdfs ...

SQL concatenating strings?

I have a query that takes input from the end user and compares it to 2 columns individually, and the two columns concatenated. SELECT f_name, l_name, (f_name + ' ' + l_name) AS full_name FROM users_table WHERE f_name = user-input OR l_name = user-input OR 'full_name' = user-input Excuse the massive syntax fail, but I assure you ...