sql-server

How to map Sets when using NHibernate Join Table per Subclass

I have the following HBMs (the sample is purely fictional, so don't try to understand the business needs) Class Document <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"> <class name="Document" discriminator-value="Document"> <id name="Id" type="long"> <generator class="native" /> </id> <discriminator /> <p...

How can you get the n most common words in a set of many rows returned in a SQL Server query?

I want to return the 10 most common words from a query in SQL server, so running against a set of rows such as this: quick brown fox slow yellow fox slow green fox would return fox slow quick brown yellow green ...

SQL Server - Get time (daylight savings aware) from another time zone

Hi, I'm looking for a way in SQL Server without using the .NET framework to find out the time in a given time zone, paying attention to daylight savings. However, this method also needs to take account for states (e.g. Arizona) that do NOT follow DST. There is a workaround if the server is located somewhere that does follow DST - subt...

t-sql COUNT on user defined function returned value

I have a CTE as below (logic removed) ;with cte_a as ( select ID, Count(AnotherID) as Counter from Table_A group by ID ) and a user defined function that takes an Id as input and returns a table. udf_GetRelatedItemIds(@Id) I wanted to just count the number of related item ids returned from the user defined function for ...

Alphabet Series Generation in SQL Server

Hi Team, I am trying to generate a series of alphabets, using SQL Server. Suppose I have a tables as follows DECLARE @Funding TABLE (FundingDetailID INT,FundingID INT, DetailDescription VARCHAR(50)) INSERT INTO @Funding (FundingDetailID ,FundingID , DetailDescription) VALUES (1,107,'Desc 1') INSERT INTO @Funding (FundingDetailID ,Fund...

SQL Same Column in one row

I have a lookup table that has a Name and an ID in it. Example: ID NAME ----------------------------------------------------------- 5499EFC9-925C-4856-A8DC-ACDBB9D0035E CANCELLED D1E31B18-1A98-4E1A-90DA-E6A3684AD5B0 31PR The first record indicates and order st...

Open databases from SQL Server like you do it with MySQL with PhpMyAdmin

i have a backup from a data base (SQL Server), i never worked with this type (always with MySQL and PhpMyAdmin to see the data). How can i see the data who is inside the backup? there is a Microsoft program to do that? like access. ...

Problem With Count()

I wants to write a query to retrieve COUNT(of employees with the salary=1000) and COUNT(of total no of employees) from the same table. any ideas?? ...

How does one deal with multiple TimeZones in applications that store dates and times?

I realize this is a bit subjective, but I'm hoping to pick everyones brain here on how they deal with multiple timezones? There are a variety of similar questions here and an equally wide variety of accepted answers. How have you delt with this in apps you've built, and what issues did you have to overcome? ...

SQL Server version of Oracle's ADD_MONTHS()

In Oracle, you can use ADD_Months to add months on the fly in the sql statement. What is the MS SQL version. Oracle Example Select TestDate, TestFrequency, ADD_MONTHS(TestDate, TestFrequency) AS FutureTestDate FROM Tests Source : java's website ...

Using System Environment variables in a sql script

In a SQL script GO :setvar DefaultDataPath "%DataDrive%:\SQL\MSSQL\Data" Will the script pick up %DataDrive% from the environment variables? If not, is there a way to get to the DataDrive environment variable from the SQL script? ...

Selecting null value from XML in SQL Server

I'm trying to select from XML that has a null as one of the attributes. Instead of returning a null, it returns a 0. What am I doing wrong? See code below to replicate: declare @a xml select @a = '<TestSet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instace"&gt; <Element> <Property1>1</Property1> <Property2>1</Property2> <...

Utilizing all Cores in SQL Sever Machine when calling SPs from C# program

Hello, I have a simple single threaded utility written in C# that inserts data into SQLServer DB using SP calls. The SQL Server machine has 8 core processor. The problem is that the utility is running very slow and 4 of the cores show max utilization in task manager and other 4 are not utilized at all. We also tried running multiple ...

Add Sort Order for FOREIGN KEY CONSTRAINT on SQL Server

How do I add the Foreign Key Sort order in the following statement: ALTER TABLE [dbo].[ActionLog] WITH CHECK ADD CONSTRAINT [FK_ActionLog_Order] FOREIGN KEY([OrderID]) I want the OrderID to be descending. ...

What is the best way to delete a joined association to a stored file in a database?

I want to know the sql statement(s) to use to delete old data and the association to the old data without deleting the more important parent table, which should live forever. I have the following tables: Step Id bigint OccurredOn datetime ScreenshotId bigint Screenshot Id bigint Data varbinary(max) I want to delete all Scr...

How to Create a join?

Is this possible: Joining tables in two databases in one server? 1.1 What connection string shall i use? Joining tables in two databases in different server? 2.1 What connection string shall i use? ...

SQL Server Provider?

How to solve this Error Msg 7308, Level 16, State 1, Line 1 OLE DB provider 'Microsoft.Jet.OLEDB.4.0' cannot be used for distributed queries because the provider is configured to run in single-threaded apartment mode. ...

Sql function to append column

Hi, Lets say I have a table that looks like this: Name value 1 Ford "some text here and there." 2 Honda "More Text Again" How can I write a sql function that will append me the 'value' column of all of the rows. so the result would be sometext here and there. More Text Again also it would be nice if I can...

sql per month identity

is it possible to create a per month identity ? basically what I need is create table ( id identity primary key regDate DateTime not null, regDateNumber int not null ) and when I insert data I need set the regDateNumber as an identity in the scope of the regDate's month like this: id regDate regDateNumber 1 1 jan 2008 1 2 ...

Sql Server replication over wan

Im looking at developing a simple ecommerce platform and need to replicate product and customer data to the web host over the internet so the website can run disconnected. The two options i can think of at present are using enterprise messaging and database replication. Im leaning towards database replication over enterprise messaging ...