sql-server-2008

How to reset the 'role settings' in SQL Server 2008?

After customizing the role settings (changed the 'public' role, just tick everything to Deny, then I set it back), all of my users cannot login, except to give them the sysadmin permission. So, I want to reset the role settings, is there any way to do that? ...

database design pattern: many to many relationship across tables?

I have the following tables: Section and Content And I want to relate them. My current approach is the following table: In which I would store Section to Section Section to Content Content to Section Content to Content Now, while I clearly can do that by adding a pair of fields that indicate whether the source is a section or...

C# insert string to database issue

Hello everyone, I am using VSTS 2008 + C# + .Net 3.5 + ADO.Net + SQL Server 2008. I have some C# string type variables, and I want to insert them into database as type DateTime, any code samples? My problem is how to do the conversion from string to database DateTime type. thanks in advance, George ...

How to convert float to varchar in SQL Server

I have a float column with numbers of different length and I'm trying to convert them to varchar. Some values exceed bigint max size, so I can't do something like this cast(cast(float_field as bigint) as varchar(100)) I've tried using decimal, but numbers aren't of the same size, so this doesn't help too CONVERT(varchar(100), Cast(f...

Concatenating large number of rows into a single string

I have a table containing a large number of rows. Each row has 2 columns which I need to use - the first is some HTML formatting and the second is the text. I need to concatenate all these rows into a single string value so that I can e-mail this massive string. Due to the large number of rows I can't use a VARCHAR variable - I have t...

help with query - update from 2 tables

hi i have 2 tables table1: num,X,Y table2: num,X,Y i need to update X and Y in table1 where table1.num = table2.num how to do it ? i need it in Oracle query (i think that in sql server it will work too) thank's in advance ...

linked server to db2 error on select

i am using oledb driver for db2 NT 7.2 to create linked server the connection is fine but whenver i select on some tables i got this error The OLE DB provider "DB2OLEDB" for linked server "xxxxxx" supplied inconsistent metadata for a column. even if i did not include the column in the select. SSIS same it not to have this problem becau...

SQL transform table query

Hi, I got a problem transforming a table that looks like this PropertyName | PropertyValue --------------------------------- color red color blue size big size small into this: Color | Size --------------------------------- red big red small blue big blue small How can I achieve this? Thanks in advance for any ...

SqlServer constrain field value dependent on another field value

As the question title, is there a way to do this? eg: DrivingLicence --------------- CanDriveCar (bool) CanDriveMotorbike (bool) CanDriveBus (bool) You can't drive a bus without a car licence, so I want the DB to throw an exception if anyone tries to give someone a bus licence when they haven't a car licence. ...

Multiple contact XML field updates SQL 2008 R2

Hi, I'm not sure of the soundness of the following architecture, but right now, the following information is for a prototype at this time. I have a stored procedure that currently lets me: Pass an owner memberID and say an ID for a new event record In the member table, I have an XML field say called events, and the new event ID gets a...

C# application accessing remote sql server 2008 instance ... not working

I have a console app that needs to connect to a remote sql server 2008 instance.... this particular line throws an error even though i have access to that database... connection.open() is the line that is throwing the error... ...

SQL Server 2008 and HashBytes

Good Day Sir/Madame! ^_^ I'm quite a novice when it comes to sql, so please forgive my ignorance. I have quite a large nvarchar which I wish to pass to the HashBytes function. I get the error: "String or binary would be truncated. Cannot insert the value NULL into column 'colname', tbale 'table'; column does not allow nulls. ...

Why can't I connect to SQL Server Express 2008 with sqlmetal 1.00.30729?

I'm trying to connect to my local Sql Server Express 2008 R2 instance (v 10.50.1600) to generate classes via sqlmetal.exe (1.00.30729) and I get the following error: Error : Failed to generate a user instance of SQL Server. Only an integrated connection can generate a user instance. The connection will be closed. I can connect via S...

Linked Tables - SQL Server 2008 to SQL Server 2005

Hey all, I have a database server that currently has two databases, call them [A] and [B]. [A] is the standard database used for my application [B] is used by another application (that puts considerable load on the server), however, we use a few tables sparingly (that are shared between my application and the primary application that ...

User Defined Function Best Practice

Hi All, I am contemplating using some user defined function calls within some of my queries instead of using a bunch of inline case statements. The inline statements will probably perform better, but the functions make it so much easier to view and possibly maintain. I just wanted to get an idea of what the typical best practice is fo...

import related tables from Access into SQL Server 2008

In SQL Server 2008 I had remade the database structure similar to Access. I need to import a couple of related tables but I am worried that the foreign keys won't match with the autonumber fields from the related tables. ...

How to design Query for creating dynamic columns from rows

I have data Table1 ID Name ----------- 1 n1 2 n2 3 n4 Table2 FID YearS Val ---------------------- 1 2008 Up 1 2009 Down 1 2010 Up 2 2000 Up 2 2001 Down 2 2002 Up 2 2003 Up 3 2009 Down 3 2010 Up I want to return data in following format:...

How to get the month from a string in sql?

I have to get the month from a column which stores string in format - Column ---------- `Feb2007' 'Sep2008' So if the value was 'Feb2007' then I need to get back 2 or else if the value was 'Sep2009' then I should get back 9. Is there inbuilt function in SQL Server 2008 to achieve something like this? ...

SQL to find runs of matching values

I have the following table called [Store_Sales] - Store Date Sales 1 23/04 10000 2 23/04 11000 1 22/04 10000 2 22/04 10500 1 21/04 10000 2 21/04 10550 I want a SQL that will return a "run" of similar values in the Sales column for a particular store. For exampl...

SQL Server 2008 R2 Query Designer: How to get a "picture" from a SQL statement?

I am using the SQL Server 2008 R2 "Query Designer" to design my SQL statements. np at all. But can this also made backwards? Means how to get a "picture" like the Designer does from a SQL statement? ...