sql-server

sql IN operator

Hi. I have the sql below but can not get it to work select product_category, ( select top 1 sub_category from sub_categories where product_category IN (keywords) ) as s from products; product category is Baby Gift Baskets and the keywords field is Baby Gift Baskets,Baby Gifts basically ...

Crystal Report 8.5 + SQL Server 2008 - connection bug

I have issues with connection in application that uses Crystal Report. Issue occurs when CR component initializes connection to database. Application crashes at that point. But when I initialize connection to some directory on server via remote desktop before application starts, then it connects to database successfully. In our projec...

Show hexadecimal dump of string

Is there any way to obtain an hexadecimal dump of a string in SQL Server? It'd be useful to troubleshoot character set and collation issues. In MySQL you'd do SELECT HEX('€uro') and in Oracle you'd do SELECT DUMP('€uro') FROM DUAL. ...

Primary and foreign key

Can we apply two primary keys in a table in anyway? ...

Stored Proc returning one row, recordset or output parameters?

Ignoring ORM / NHibernate, etc. Consider the common requirement to pass in a Unique ID and return data from a single row (if the ID is found). The two ways to do this would be to return a record set or to use output parameters. Stored proc would be called from .NET C# code - so from that point of view one requires the set up / reading ...

counting rows before processing with a cursor tsql

hi there I have a SQL Server sp using a cursor thus: DECLARE TestCursor CURSOR FOR SELECT tblHSOutcomes.strOutcomeName, tblHSData.fkHSTest FROM tblHSData INNER JOIN tblHSOutcomes ON tblHSData.fkOutcome = tblHSOutcomes.uidOutcome INNER JOIN tblHSTests ON tblHSData.fkHSTest = tblHSTests....

Installing SQL Server 2005 Reporting Services after SQL Server 2005 is installed.

I need to install SSRS. Have alreay installed SQL Server. Dosn't seem possible in Add/Remove programs and when I run the installation wizard again it seems to think its a fresh install. Whats the best appraoch for installation of SSRS after you have SQL Server installed ...

Encrypting Communication with SQL Server Database

I have a SQL Server database with some sensitive info. I want to encrypt communications between this database and a remote webservice. How is this achieved? ...

setting persistence context to read-only in jpa

we are going to be working with an old database. so it is very crucial that we do not modify the database/table/schemas under any circumstances (from the reporting modules), and as such i want to setup a persistence-context with some persistence units as read-only (for reporting modules), and some as normal JTA enabled. we have already ...

insert into <archiveTable> using top in while loop

Hi I need to archive let say Order table to OrderArchive table using SQL statement Order table has 10,000 records. I need to insert into OrderArchive table from Order with top 1000 rows in while loop. How can I achieve this in SQL Server Thanks. ...

Vs 2010 Sql DB Project fails in x64

Tried to create a SQL 2005 DB project. In Vs, New Project >> Sql Server 2005 Database project. I right click the project in solution explorer. I get this error message: An error occurred trying to load the project properties window. Close the window and try again. Cannot evaluate the item metadata "%(FullPath)". The item metadata "%(Fu...

How to get the new database size after deferred drop operations?

We've been using the sys.database_files view and the FILEPROPERTY function to get the size of the database. Unfortunately, as I have just found in the documentation, the values returned by sys.database_files are not always reliable: When you drop or rebuild large indexes, or drop or truncate large tables, the Database Engine defe...

SQL Server 2008: Why table scaning when another logical condition is satisfied first?

Consider following piece of code: declare @var bit = 0 select * from tableA as A where 1= (case when @var = 0 then 1 when exists(select null from tableB as B where A.id=B.id) then 1 else 0 end) Since variable @var is set to 0, then the result of evaluating searched case operator is 1. In the documentation of case i...

SQL Server Enterprise Manager - Mass Delete of Tables and Changing Ownership of Tables

I have pretty much no experience with SQL Server's Enterprise Manager so I am not sure if this is even possible (or hopefully laughably simple!) During an import into a database something has happened where each table has duplicated itself with two important differences. The first is that the Owner on both tables is different, the seco...

T-SQL Pivot to display One Comment field per week

I've been asked to change a pivot query that currently displays a week ending date, category and hours by date for one week in a row. I've been asked to display a comment field at the end of the row and I can't figure out how to alter the query to do this. The table is structured like this Category Date Comments Hours test...

I Get a Weird Error while Deploying a SQL Server Report

When i attempt to deploy a SQL Server Report, i get the following error: An attempt has been made to use a data extension 'OLEDB-MD' that is either not registered for this report server or is not supported in this edition of Reporting Services. (rsDataExtensionNotFound) This error occurs only when i try to deploy a certain report. Rest...

cakephp-mssql integration:how does it works

I am newbie in cakephp world when i am trying to configure cakephp with ms-sql, I am not able to connect to database. php-mssql configuration is working fine for me( though for that i uses ADODB connection ) . But nothing worked for cakephp. I searched a lot on google but none of the ways are working for me. Thanks, Ankur ...

Trigger for update multi line

Hi, I'm having a problem with this trigger: ALTER TRIGGER [dbo].[trg_B_U_Login] ON [dbo].[Login] FOR UPDATE AS BEGIN IF @@ROWCOUNT = 0 RETURN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; DECLARE @Campos nvarchar(500); DECLARE @Old...

SQL replace all instances of word in a field

Any way to do this? Replace function only replaces first instance. Thanks. ...

APOSTROPHE DYNAMIC SQL

DECLARE @SQL Varchar(Max) DECLARE @DESCR Varchar(Max) -- Customer enters description into @Descr SET @SQL = 'Update TableName SET FieldName=''' + @DESCR + ''' WHERE ID=123' The problem is when the customer enters an apostrophe into the @Descr variable. Q: In Microsoft SQL Server 2005, how do I replace all apostrophies with double apo...