sql-server

How to save byte[] using a procedure?

This stored procedure does not save the data, it seems to be a problem with the VARBINARY. I am passing a byte[] to it, but then it doesn't work. If I send this parameter as NULL it works. I'm calling the procedure with the following code: public Community AddCommunity(string name, string description, byte[] picture, User owner, int? v...

Attack on ASP site that uses a SQL server database

We have a survey site that was apparently attacked. The symptoms are identical to what was described on the following page on this site: http://stackoverflow.com/questions/3775964/xss-attack-on-the-asp-net-website. I found multiple entries in our IIS logs that included the malicious code: < / title> < script src = http : // google-s...

SQL Case with multiple fields

I have 3 fields that shows a hierachy in my application. The 3 fileds are as follows: rl.Level1 rl.Level2 rl.Level3 I am trying to show only the last level that is populated in my output. Basically this is what I am trying to do. If level3 is null then return level2 but if level2 is also null then return level1 but if level3 is not ...

How Can I Rid off Redundant Values from a Column?

This is the sample output Let me explain what's going on: The query returns all invoices # of every year along with the products that is involved in the invoice. As you see, we have two invoice in 2010...The invoices are 30463 and 30516. The invoice 30463 has 4 products, its shipping price is 105.88. As you see the shipping price is r...

How can I do something like: USE @databaseName

DECLARE @DatabaseName NVARCHAR(max); SET @DatabaseName = 'MainDb' USE @DatabaseName Wouldn't work. How to make it? ...

automate a SQL query to run every month

I have a simple SQL query that updates some date fields in a record, on a SQL Express instance. I'd like to have it run automatically every month. What is the best way of accomplishing this in SQL Server 2005 Express using the Management Studio? ...

Efficient way to retrieve multiple objects from database.

Hello, quick qestion today... what is more efficient and is there a big diffrence in performance between those to SQL Server operations. select four objects from database in four separate select queries (just fetching them by id) in one single transaction, or select it in a single query (ofcourse more complicated, with joins). I'll ...

Performance issues calling stored proc from within a stored proc

Hello, I worked on a project that had the following requirement: TableA is the parent table. Whenever any children records of TableA are updated the 'LastActivityDate' field in TableA should be updated with the current UTC date. Now, I know there are many ways of doing this. My post is NOT about the many different ways this coul...

Violation of UNIQUE KEY constraint on INSERT WHERE COUNT(*) = 0 on SQL Server 2005

I'm inserting into a SQL database from multiple processes. It's likely that the processes will sometimes try to insert duplicate data into the table. I've tried to write the query in a way that will handle the duplicates but I still get: System.Data.SqlClient.SqlException: Violation of UNIQUE KEY constraint 'UK1_MyTable'. Cannot insert ...

SQL Server Transaction Log Explorer/Analyzer

Does anybody have suggestions for a 3rd party SQL log analyzer that will allow a DBA to roll back a transaction from the transaction log? Any experiences to be shared? This isn't a: "Help! I blew up my database." question. I'm looking to have a plan in place before somebody deletes 10,000 of the wrong rows. I know that Apex makes a pro...

SQL Query: Each GROUP BY expression must contain at least one column that is not an outer reference.

Getting this error: Each GROUP BY expression must contain at least one column that is not an outer reference. RowId ErrorDatetime ErrorNum ErrorMessage 824 2010-09-24 08:01:42.000 9001 Account 55 not found 823 2010-09-24 08:00:56.000 9001 Account 22222222222 not found 822 2010-09-24 05:06:27.000 ...

Subtracting count of rows in subquery from current query

In SQL Server 2005, given the following resultset ID | InstanceNumber | IsArchived 5000 | 1 | True 8347 | 2 | True 9343 | 3 | False 11048 | 4 | False What I would like to return is this: ID | InstanceNumber | IsArchiv...

SQL query that looks within the same table

Apologies - am not good at SQL. Perhaps this is a simple query - I don't know. What I have is a basic forum table - e.g. id poster title type content postedon parentID in this scheme, if a user asks a question, it is type = 0, and if it is an answer, type = 1. If the entry is an answer, I update the parentID to the id on the question...

I Need some sort of Conditional Join.

Okay, I know there are a few posts that discuss this, but my problem cannot be solved by a conditional where statement on a join (the common solution). I have three join statements, and depending on the query parameters, I may need to run any combination of the three. My Join statement is quite expensive, so I want to only do the join w...

Sql query to convert nvarchar to int.

I have to query for total amount of a column using an aggregate function. The column data type is NVARCHAR(MAX). How can I convert it to Integer? I have tried this: SELECT SUM(CAST(amount AS INT)), branch FROM tblproducts WHERE id = 4 GROUP BY branch ...but I'm getting: Conversion failed when converting the ...

How to come to limits of 8060 bytes per row and 8000 per (varchar, nvarchar) value?

Comining from my question [1] where I was explained how to derive 8078 bytes of data per page in MS SQL Server. If to calculate the number of bytes per page used for data (without overhead) storage of only one row with one column of non-indexed fixed size type record (according to [1], i.e. [2]), then I come to 8087 bytes (per page)...

No mapping exists from DbType System.DateTimeOffset to a known SqlCeType.

I have a SQL Server 2008 database that contains DateTimeOffset objects. As per this page, SQL Server Compact provides support for replicating the new data types in SQL Server 2008 such as date, time, datetime2, datetimeoffset, geography, and geometry. The new data types in SQL Server 2008 are mapped to nchar, nvarchar, image, etc. F...

How to use git as source control provider for management studio

Hi, Can we use GIT as the source control for sql management studio? ...

SQL Server: how to query when the last transaction log backup has been taken?

I would like to query for all databases (in SQL Server 2008 instance) date when the last transaction log backup has been taken. How to do that? I know that this information is somewhere, but I don't know where. ...

Unique index or unique key?

What is the diffrence between a unique index and a unique key? ...