sql-server

In SQL, can i convert a "|" separated list of IDs to a list of their values?

Using states as an example, my current data looks like StateAbbrev | NumOfResults ----------- ------------ MD | 5 VA | 2 DC | 7 MD|VA | 2 CA|NY|VA | 1 I would like it to output the following StateName | NumOfResults --------- ------------ Maryland ...

sql Query Issue

Hello experts, I have a table as shown below Q_ID DeptID EmployeeName City 100 100 testest abcd 100 101 tata cdd with 100K records. I need a query which should fetch all records with same Q_ID but different DEPTID. Please help. Thanks ...

SQL Server Table Dump - Not All Columns

I'm trying to do an SQL Server dump of a couple of tables in a database (Microsoft SQL Server). We don't have write access to the DB, so we can't do what I was originally thinking (create temp db, copy tables (minus the columns we don't want into the temp db, and then dump that db). I really can't figure out a way to do this. A csv expo...

How many tables are recommended in a SQL Server Express database?

I'm a newbie.How many number of tables are recommended in a SQL Server Express database? mainly attaining best performance speedwise as an objective. Is it generally recommend to use two databases as compared to one for a single application? Your quick response will be highly appreciated ...

Is it true that SQL auth is only great for multiple role apps ??

Hello, I believe Windows auth is the best practice to use to connect to SQL DB. I am hear talking about application user account.. Is it true that SQL auth is only great for multiple role apps and window auth is only good for single role app? I never heard that windows auth with muitple role os only good for smaill internal app? mult...

sp_addlinkserver using trigger

I have the following trigger, which causes an error when it runs: CREATE TRIGGER ... ON ... FOR INSERT, UPDATE AS IF UPDATE(STATUS) BEGIN DECLARE @newPrice VARCHAR(50) DECLARE @FILENAME VARCHAR(50) DECLARE @server VARCHAR(50) DECLARE @provider VARCHAR(50) DECLARE @datasrc VARCHAR(50) DECLARE @location VARCHA...

Getting count of related tags

I recently asked this question to get related tags like in Stack Overflow: http://stackoverflow.com/questions/1648190/what-is-the-query-to-get-related-tags-like-in-stack-overflow I would like to show the count like in Stack Overflow, so with each related tag, what is the count of this other tag on questions with the first tag? Because ...

While debugging a CLR Stored Procedure VS2008 is giving error like 'cancelled by user'

please any one help me while debugging a CLR sp am getting error like "cancelled by user" i think i need to enable something? ...

Getting related tags from SQL Server when you have filtered down

I asked this question before and got a great working answer. http://stackoverflow.com/questions/1648190/what-is-the-query-to-get-related-tags-like-in-stack-overflow but i realized that SOF actually takes it one step further as it supports multiple tag drilldown what i mean is, if click on the tag C#, that will filter to 20,000 questi...

Sql Server paging rows by offset - without 'ORDER BY'

A production table of mine contains over a million records. An requirement calls for a paging query to retrieve records by OFFSET and LIMIT parameters(similar to MySql's LIMIT clause), without sorting the result set, just as rows' natural order are in a table-scan, since 'ORDER BY' generates unacceptable performance impact, including 'OR...

SQL Query - Ensure data in a table covers a year, with no date overlaps

I have a table called tblRentalRates with the following columns: rate_id (int) rate_startdate (datetime) rate_enddate (datetime) weekday_rate (money) weekend_rate (money) I want to accomplish the following goal: Write a query that will check the contents of the table and ensure that for the current year, that the data covers ...

SQL CE Compact 3.5 Identity columns for a table.

Is there a query I can write against an INFORMATION_SCHEMA or against the system tables to determine if a column is an identity column in SQL CE version 3.5? ...

is there an equivalent of the "IN" function for adding "AND"s to queries

i have the following tables in sql server: photoalbumsTable: album_ID album_caption albumtagmap id album_id tag_id albumtags id tag_name i have the following query which will show me where t.tag_name is in "Trips" OR 'Beach": SELECT b.* FROM albumtagmap bt, photoalbums b, albumtags t WHERE bt.tag_id = t.id...

SqlServer Rand() question

I am writing a procedure where each call it needs to get a single random number. This procedure is called from our .net web service. I tried implementing this using rand(). However, when I have multiple calls to the stored procedure within milliseconds, I am getting a lot of collisions in that the same random number is being generat...

Query through linked server is very slow

I have 2 SQL 2005 servers SRV1 and SRV2. SRV2 is the linked server on SRV1. I run a storep proc with params on SRV2 and it is completed immediately. But when I run the same proc through the linked server on SRV1, for example EXEC [SRV1].DB_TEST.dbo.p_sample_proc it takes about 8-10 minutes to complete. After restarting SRV2 the problem ...

Problem with SQL Server Select Replace()

I am successfully executing the following query in SQL Server 2008 built into VS2008: SELECT REPLACE(image32, 'img', 'images/Products') FROM Product but when I do a select * from product query, I am given the old results. Whats going on? Why isnt my data being updated? Did I just answer my question? Do I need to throw in an Update ...

Error in when comparing British format date in where clause.

When I run this in sql server2005 I got error. select * from productratedates where RateDate BETWEEN '31/10/2009' AND '03/11/2009' Error: The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value. But When I run this in SQl server 2005. It is perfectly all right. select * from productrate...

Sql query to Group by day

I want to list all sales, and group the sum by day. Sales (saleID INT, amount INT, created DATETIME) Update I am using SQL Server 2005 ...

Query to get sum of an employees commission

Query to get total commissions for an employee, and update their totalCommission column in the employee table. This query is run every few days (batch). The rules: 1. an employee can only get a maximum of $100/day of commision, if they get more than $100 it just gets set to $100. Tables: Employee (employeeID INT PK, totalCommissi...

Find the longest sequence of a value in a table

This is an SQL Question, I think it is difficult one - I'm not sure it is possible to achieve in a simple SQL sentence or a stored procedure: I want to find the number of the longest sequence of the same (known) number in a column in a table: example: TABLE: DATE SALEDITEMS 1/1/09 4 1/2/09 3 1/3/09 3 1/4/09 ...