sql-server

TSQL: How to get a list of groups that a user belongs to in Active Diretory

I have two queries that retrieve all groups and all users in a domain, Mydomain --; Get all groups in domain MyDomain select * from OpenQuery(ADSI, ' SELECT samaccountname,mail,sn,name, cn, objectCategory FROM ''LDAP://Mydomain/CN=users,DC=Mydomain,DC=com'' WHERE objectCategory=''group'' ORDER BY cn ') --; Get all users in dom...

T-SQL Output Clause: How to access the old Identity ID

Hi There, I have a T-SQL statement that basically does an insert and OUTPUTs some of the inserted values to a table variable for later processing. Is there a way for me to store the old Identity ID of the selected records into my table variable. If I use the code below, I get "The multi-part identifier "a.ID" could not be bound." error...

SQL Server 2005- Add area code to records shorter than 10 characters

Can anyone come up with a SQL routine or ideas to systematically append an area code to the beginning of every field in our SQL Server 2005 database that does not have an area code in it? Perhaps someone could tell us how to return only rows that are less than 10 characters long and how to append the 3 digit area code to the beginning ...

Search if a string word exists between two different tables in a comma-delimited field

I have two tables: EmployeeTypeA table Name varchar(2000) field contains - 'john,sam,doug' EmployeeTypeB table Name varchar(2000) field contains - 'eric,sam,allen,stephanie' What is the most efficient way to return a true or false when a name is found in both lists using MS SQL? This needs to be done within a stored procedure so I ca...

Change case of a column name

I have a table in my warehouse that has columns in all uppercase. It scripts out like this: CREATE TABLE [dbo].[Outlet]( [OUTLET_KEY] [varchar](10) NOT NULL, [OUTLET] [varchar](8) NULL, [CITY_CODE] [varchar](4) NULL, [OUTLET_NAME] [varchar](25) NULL, [COUNTRY_CODE] [varchar](3) NULL, [EXTENDED_CATEGORY_CODE] [var...

Method of simulating views on a SQL Server with read-only access?

I'm trying to do quite a lot of querying against a Microsoft SQL Server that I only have read only access to. My queries are needing to work with the data in very different structure from how the DB architecture is. Since I only have read access, I can't create views, so I'm looking for a solution. What I'm currently doing is using com...

How do I define a work week in SQL Server 2000?

I need to split a report by work week, and our work week is Saturday through Friday. How would I convert an ISO week from DATEPART(WW, ) into a work week? ...

COALESCE with NULL

I found this snippet of SQL in a view and I am rather puzzled by it's purpose (actual SQL shortened for brevity): SELECT COALESCE(b.Foo, NULL) AS Foo FROM a LEFT JOIN b ON b.aId=a.Id I cannot think of a single reason of the purpose of coalescing with null instead of just doing this: SELECT b.Foo AS Foo FROM a LEFT JOIN b ON...

SQL Server delete trigger - row handle referred to a deleted row or a row marked for deletion

I have a delete trigger on a table which is used to delete entries from a table in an another database. CREATE TRIGGER [dbo].[Trigger_Contracts_Delete] ON [dbo].[Contracts] AFTER DELETE NOT FOR REPLICATION AS IF @@ROWCOUNT = 0 RETURN DELETE seconddb.dbo.second_table WHERE contractId IN (SELECT d.ContractID FROM deleted d) Whe...

Executing multiple dynamic statements together over linked server

I need to execute three dynamic SQL statements synchronously on a linked server (SQL Server 2005) like this: declare @statement nvarchar(max); set @statement = 'exec ' + @server_name + '.' + @database_name + '.dbo.Foo;exec ' + @server_name + '.' + @database_name + '.dbo.Bar;exec ' + @server_name + '.' + @database_name + '.dbo.BigTime';...

VB.Net 3.5 and SQL Server 2005 Windows Chat Application

Hi Currently following is the project I need to submit for my college assignment: A vb.net chat application with a ms sql server 2k5 backend, max 100 users with file transfer, one to one and group chat facility. Admin will create chat rooms which will be password protected for group chats. We will need to implement multithreading to fect...

How to get the SQL Server name and Role used by Sharepoint Server in Server farm?

I have a sharepoint server farm like the following. Machine1: Test_DB in this machine i have installed SQL Server as named instance. (Test_DB\sqlserver) Machine2: Test_appsrv Application server complete installation Machine3: Test_web in this installed sharepoint as webfront end. In my central admin I am seeing all the ...

No SQL Server Express logins have permission to create db

I cant create a new db because there are only 2 logins: sa BuiltIn\Users I get permission denied when trying to create the db even though I am the admin. How can I add a user with permissions at this point or must I reinstall? ...

SQL Server String column as a unique key

I am using a SQL server table to keep related information with a URL . So there is a Column as "URL" and its type is VARCHAR . In the application we have to use this URL as a unique key to query for information (We are using something like SELECT * FROM Table WHERE URL = "www.google.com\ig") Is there any disadvantages or known drawbacks...

SQL Server get next previous rows from a table based on a date

I have the following SQL Server query and I am trying to get the next and previous row from a given Id. All works great unless there are two/more dates that are the same, then my logic breaks down. If you set @currentId = 4 then I get back id 7 (it should be id 6) for the prev If you set @currentId = 6 then I get back id 2 (it should ...

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible.

I am getting the above error when I upload my app to the hosting company.(asp.net) DB is a local sql mdf in app_data directory. on local asp.net dev server everything is ok. I am using LINQ to SQL Classes, is there anything that can be related to that? Thanks in advance ...

foreign keys in sql server 2005

I having trouble creating a foreign key in sql 2005. my primary key table has a primary key that spans 2 columns. I want to create my foreign key so it references a column in my primary table but I want to specify a static value for the second column - is this possible? ...

Best way to extract date from SQL Datetime field in C#.Net?

What is the best way to extract date from SQL Datetime field in C#.Net? ...

Moving client data from one database to a new one.

Our application architecture allows us to host multiple clients in a single database, and also host multiple databases. This allows us to scale out by distributing clients across multiple databases. For example, 20 clients can be in database A, and another 15 could be in database B. We use a ClientID field in almost every table to par...

c#/sql-server, trying to get data to two ddl's from two tables...in one sqlDataReder

Hi all, Well, i am tring to do something nice (nice for me, simple for you guys), i was told i can do it, but i have no idea where to start. I have two DDL's in a page, i need on page_load to popolate both, each one gets data from deferent table with no relaition between them (suppliers/catagories). i know how to do it with two DB conne...