sql-server

Why can't I apply a criteria on a sub-query?

What I'm trying to do is this: select Store.Id, (select COUNT(*) from StoreProduct where StoreProduct.Store_id = Store.Id) as _count from Store where _count > 3 SQL Server says it's invalid because the column name '_count' is invalid. Why it's invalid if I'm declaring it? ...

Why can't I use alias in a count(*) "column" and reference it in a having clause ?

I was wondering why can't I use alias in a count(*) and reference it in the having clause. For instance: select Store_id as StoreId, count(*) as _count from StoreProduct group by Store_id having _count > 0 Wouldn't work.. But it works if I remove _count and use count(*) instead. ...

How to escape a native SQL function in perl bind_param()?

So I have the following snippet code: my $sql = "INSERT INTO mytbl (first_name, last_name, birthdate) VALUES (?, ?, ?)"; my $sth = $dbh->prepare($sql) or die "Error:".$dbh->errstr; $sth->bind_param(1, $fname); $sth->bind_param(2, $lname); $sth->bind_param(3, $bdate); $sth->execute() or die "Execution failed: " . $dbh->...

Configuring DBMail with SQL Server (2005) Management Studio Express

Hello and good day, The title sums up my dilemma: "Configuring DBMail with SQL Server Management Studio Express" Anyone out in this august assemblage can help me out? Thanks in advance ...

Is this an effective and efficient SQL Query or is there a better way?

We have a passwords table which references a user table. Records never get deleted from the password table so if a user changes their password, a new entry with a more recent Created date gets inserted. The hash of the password is salted with various things, most importantly the created date of the actual record. In a stored procedure...

At what point is a simple dataset better stored in SQL Server than a CSV file when using ActiveRecord

I have a dataset consisting of roughly 10000 5 field records. I need to be able to retrieve a record based on the value in one field, which is a unique string. Each record will likely only be accessed once or twice. The application accessing the data uses Castle with ActiveRecord, backed onto SQL Server 2005. I recognize that at some p...

Parent Child table record - Building SQL query

Here is my table and data of these tables Table name: Code CID Code 1 abc 2 def 3 xyz Table Name : Details ID Name CID 1 a 1 2 b 2 Resultant Table: ID Code Name 1 abc a 2 abc Null 3 def b 4 def Null 5 xyz Null 6 xyz Null I nned to ...

How to keep on transaction when it fails for some rows?

Hello! I want that when I execute a query for example DELETE FROM Contact, and an error is raised during the transaction it should delete the rows that are able to be deleted raising all the relevant errors for the rows that cannot be deleted. ...

SQL Server 2008 shredding XML data - cant get element text in rowset!

Please consider this simple example. I can't get the text of the state element 'red' or 'blue' Please help!!!!! this is driving me batty DECLARE @xml XML; SET @xml = '<capitals> <state name="Alabama" abbreviation="AL" capital="Montgomery" >red</state> <state name="Alaska" abbreviation="AK" capital="Juneau" >bl...

SQL Server, T-SQL is there a faster way to substring the following string in my question?

I have strings like OPEN SYSTEMS SUB GR (GM/BTIB(1111)/BTITDBL(2222)/BTVY(4444)/ACSVTYSAG) in my database under my GROUPS Column. What I want to do is to extract the 2222 from that string. The code I am using is like that. SELECT SUBSTRING(GROUPS, CHARINDEX('(',GROUPS, CHARINDEX('(',GROUPS, CHARINDEX('(',GROUPS,0)+1)+1...

How to access temptable after creating it dynamically.

Hi.. I am using the statement SELECT * INTO #gsig_ref FROM gsign WHERE [name] NOT LIKE 'RESERVE%' OR [name] NOT LIKE 'Spare%' EXECUTE('SELECT * INTO #db1 FROM ' + @db1) EXECUTE('SELECT * INTO #db2 FROM ' + @db2) where @db1 will be supplied at runtime (for eg @db1 = '#gsig_ref') If I say select * from #db1......

How can I tell what edition of SQL Server runs on the machine?

I am running SQL Server 2005 but I am unsure which edition this is. How can I decide what edition (Express, Standard, Enterprise etc) is running on the machine? ...

How to Change from Sql Server Windows mode to Mixed Mode *Using SQL* (SQL Server 2008)

How to Change from Sql Server Windows mode to Mixed Mode using SQL through say QueryExpress or QueryAnalyser? ...

Shopping cart with asp.net and SQL Server reserve items

Hey everyone, Question has been asked with no answers over a month ago: http://stackoverflow.com/questions/1806739/shopping-cart-reserve-product/2070884#2070884 Anyway, basically I have a shopping cart for my site in ASP.NET using SQL Server. When a user adds an item to the shopping cart I need to set a value in the product table to re...

How to show the tablenames with foreign key = myId

I am trying to figure out where my primary keys of a table with translation per language resides as a foreign key. This is what i already have ... SELECT * FROM ( SELECT TM.seqtrans, T.trans, CASE T.seqlang WHEN 1 THEN 'NL' WHEN 2 THEN 'FR' ...

Want data from table in SQL server

I have table data like this id id1 name 1 1 test1 1 1 test1 1 2 test2 2 1 test1 2 2 test2 3 1 test1 3 2 test2 3 2 test2 now from table i want the data as below like for id = 1 order by id1 asc the first name = test1 so i want the first two row id id1 name 1 1 test1 1 1 test1 not third r...

SQL Server Management Studio Clear Cache Code Completion

If you change a table, then code completion doesn't work anymore when writing a query in SQL Server Management Studio. Is there a way to clear this cache? (SQL Server 2008) ...

'The SELECT permission was denied on the object ' when working with views on separate schema

Note: This is a community wiki entry and is mainly to document a problem together with its solution. I was hardly able to find information on the net to solve this. Hope it helps someone! I have a SQL-Server 2005 DB with the data tables being on the dbo schema. For a new component on the project, I created a new data access layer (us...

How long does it take to translate SQL Server queries to MySQL?

I have been tasked with estimating the amount of time it will take to rewrite the data access layer of a .NET application from using SQL Server to use MySQL. It is not up for discussion whether this will happen or not...just how long will it take. I have estimated all of the work except for translating the stored procedures in SQL Serv...

Storing and retrieving images with MVC and Sql Server

I am designing an prototyping an app the needs to store images, similar to facebook. This will be a public facing site and I am not sure how many users I will end up with but what I am looking for is a way to efficiently retrieve them. So far I am thinking of storing them in SQL Server varbinary columns. Is this a good idea? I have the ...