sql-server-2008

SQLCMD Syntax error when running script that runs fine in management studio

When I run the this select '$(''test'')' in SQL Management Studio 2008 it returns $('test') When I run sqlcmd -S SERVER -E -d DATABASE -q "select $(''test'')" on the command line it returns Sqlcmd: Error: Syntax error at line 1 near command '''. If I remove the dollar sign it works. Is the "$" a special character? Is this a sqlcmd ...

How can I show the Percentage Value On my Legends in Report (Pie Chart)

I'm new to SQL Server. how can I add the values of my Pie Chart to the Legend next to the Series fields? In this case I want the percentage. For example: United States 43.2% Canada 22% etc. ...

Visual studio 2010 and Sql Server

Do visual studio 2010 include already Sql Server instance, or I need to install Sql Server developer edition to develop an application that need a Sql Server db. If it installs a Sql Server express edition, it this enough or it's better to have Sql Server developer edition? ...

Foreign key onto weak entity set in MS SQL Server 2008?

I'm using Microsoft SQL Server 2008 Management Studio to create a relational schema by following an Entity-Relationship diagram. (included below; unrelated details removed) Until now, primary and foreign keys have been working as expected. But when I try to create a foreign key from the entity relationship takes onto the weak entity s...

How to see this format hh:mm from hh:mm:ss in SQL Server 2008 query ?

Hi How to see this format hh:mm from hh:mm:ss in SQL Server 2008 query ? Thanks in advance ...

MS Access 2007: "Attachment" data type equivalent in SQL Server 2008?

What is the "Attachment" data type's equivalent in SQL Server 2008? ...

Losing DateTimeOffset precision when using C#

I have a SQL Server table with a CreatedDate field of type DateTimeOffset(2). A sample value which is in the table is 2010-03-01 15:18:58.57 -05:00 As an example, from within C# I retrieve this value like so: var cmd = new SqlCommand("SELECT CreatedDate FROM Entities WHERE EntityID = 2", cn); var da = new SqlDataAdapter(cmd); D...

doublechecking: no db-wide 'unicode switch' for sql server in the foreseeable future, i.e. like Oracle

Hi all, I believe I know the answer to this question, but wanted to confirm: Question Does Sql server (or will it in the foreseeable future), offer a database-wide "unicode switch" which says "store all characters in unicode (UTF-16, UCS-2, etc)", i.e. like Oracle. The Context Our application has provided "CJK" (Chinese-Japanese-Kor...

Debugging dynamic sql + dynamic tables in MS SQL Server 2008.

Hi, I have a messy stored procedure which uses dynamic sql. I can debug it in runtime by adding print @sql; where @sql; is the string containing the dynamic SQL, right before I call execute (@sql);. Now, the multi-page stored procedure also creates dynamic tables and uses them in a query. I want to print those tables to the console ri...

Cascading Deletes in SQL Sever 2008 not working.

I have the following table setup. Bag | +-> BagID (Guid) +-> BagNumber (Int) BagCommentRelation | +-> BagID (Int) +-> CommentID (Guid) BagComment | +-> CommentID (Guid) +-> Text (varchar(200)) BagCommentRelation has Foreign Keys to Bag and BagComment. So, I turned on cascading deletes for both those Foreign Keys, ...

Can you create a trigger on a field within a table?

Is it possible to create a trigger on a field within a table being updated? So if I have: TableA Field1 Field2 .... I want to update a certain value when Field1 is changed. In this instance, I want to update Field2 when Field1 is updated, but don't want to have that change cause another trigger invocation, etc... ...

Storing varchar(max) & varbinary(max) together - Problem?

I have an app that will have entries of both varchar(max) and varbinary(max) data types. I was considering putting these both in a separate table, together, even if only one of the two will be used at any given time. The question is whether storing them together has any impact on performance. Considering that they are stored in the hea...

Unable to login to SQL Server + SQL Server Authentication + Error: 18456

Hello I have created login account on my localhost\sql2008 Server (Eg. User123) Mapped to Database (default) Authentication Mode on SQL Server is set to both (Windows and SQL) But login to SQL Server fails with following message (for User123) Note: Have checked multiple time that UserName / Password are typed in correctly Error De...

Date & time query question (SQL Server 2008)

hi I have table that contain date and time field. id|date|time ========= 1|01/01/2001|10:45 2|01/02/2002|11:45 3|01/03/2003|12:45 4|01/04/2004|12:55 I need to know the difference between the MAX(date) and the MIN(date) And the MAX(time) and the MIN(time) Something like.... MAX(date)-MIN(date) ???..... Thanks in advance ...

SSIS to copy data from one table to another, where not in destination table

I'm in the process of creating an SSIS package on a server (server1) that looks at the data in a sql db on another site (server2) and copies relevant rows across. The SQL statement required is: SELECT * FROM server2.ordersTable WHERE OrderID Not In (SELECT OrderID FROM server1.ordersTable This selects data from server1 which isn't in...

How to select the value of the xsi:type attribute in SQL Server?

Considering this xml document: DECLARE @X XML (DOCUMENT search.SearchParameters) = '<parameters xmlns="http://www.educations.com/Search/Parameters.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt; <parameter xsi:type="category" categoryID="38" /> </parameters>'; I'd like to access the value of the attribute "type". Ac...

Keeping SQL out of the buffer or finding a way to improve page life expectancy?

My SQL Server 2008 server gets flooded with dynamic SQL from one stored procedure. I am wondering whether I can tell SQL Server not to store this one stored procedure in the pool as it doesn't matter too much whether it executes quickly. Perhaps there is an equivalent of (nolock) for (nobuffer) or similar? Any ideas? ...

Why is my left join not returning nulls?

In sql server 2008, I have the following query: select c.title as categorytitle, s.title as subcategorytitle, i.title as itemtitle from categories c join subcategories s on c.categoryid = s.categoryid left join itemcategories ic on s.subcategoryid = ic.subcategoryid left join items i on ic.itemid = i.itemid and i.site...

t-sql string concatenation

i have a table that has following column Type -------- type 1 type 2 type 3 How can i convert the above to a string like ('type 1', 'type 2', 'type 3') I want to use the output in my t-sql query with IN clause. Something like select * from TableA where SomeColumn IN ('Type 1','Type 2', Type 3') I used to following to come up with ou...

Is there such a thing as too many tables?

I've been searching stackoverflow for about an hour now and couldn't find any topics related, so I apologize if this is a duplicate question. My inquiry is this. Is there a point at which there are too many tables in a database? Even if the structure is well organized, thought out, and perfectly facilitates the design intent? I have a d...