sql-server

SQL Server: is it possible to get data from another SQL server without setting linked server?

I need to do the following query (for example): SELECT c1.CustomerName FROM Customer as c1 INNER JOIN [ExternalServer].[Database].[dbo].[Customer] as c2 ON c2.RefId = c1.RefId For some security reason my client doesn't allow me to create a linked server. The user under whom I execute this query has access to both tables. Is it possibl...

SQL - create database and tables in one script

Sorry if already asked, but I can't find anything on this. I am moving something over from MySQL to SQL Server I want to have a .sql file create a database and tables within the database. After working out syntax kinks I have gotten the files to work (almost). If I run IF db_id('dbname') IS NULL CREATE DATABASE dbname it works ...

Insert from table1 to table2 on insert trigger.

I'm very new to SQL so forgive my ineptitude. I'm trying to write a trigger that, on insert to table 1, inserts that record into table 2. table 1 is [rps_lab_dev].[dbo].[Lab_Employee_Time_Off] table 2 is [dbo].[Lab_Employee_Time_Off_Detail] CREATE TRIGGER updatetrig ON [rps_lab_dev].[dbo].[Lab_Employee_Time_Off] FOR INSERT AS ... ...

call a web service from T-SQL in Sql Server 2008

Is there a way to call a HTTP web service from T-SQL (no SQLCLR) in Sql Server 2008? I just need to send information out, I do not need to receive anything into T-SQL. Thanks. ...

Storing many bits -- Should I use multiple columns or a single bitfield column?

Hello, I am designing a User table in my database. I have about 30 or so options for each user that can be either "allow" or "disallow". My question is should I store these as 30 bit columns or should I use a single int column to store them and parse out each bit in my application? Also, our database is SQL Server 2008 and 2005 (depen...

Deadlocks - Will this really help?

So I've got a query that keeps deadlocking on me. People who know the system well can't figure out why the sproc is deadlocking, but they tell me that I should just add this to it: SET NOCOUNT ON SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED Is this really a valid solution? What does that do? ...

t-sql create user and grant execute on permission for stored procedures

Hi I have a script which creates a database, stored procs, views, tables, udf. I want to include a script to create a user 'user_1' and give execute permission on the database. update I tried following to create grant exec command for all stored procs use DB; go declare @permission varchar(max) select @permission = COALESCE(@permi...

sql server query to return a value

Below is my query which is updating a record in the User table , I want the query to return the UserId which was updated, How can I do this? UPDATE USER SET GroupID = @New_GroupID FROM USER LEFT OUTER JOIN DOCUMENTS ON User.UserID = Documents.UserID WHERE (Documents.UNC = @UNC) AND...

Restricted Access to analysis services

What is the equivalent of RESTRICTED_USER database state in Analysis services? When we try to process OLAP cubes, it fails because of active user connections to teh cubes. Is there a way to restrict the user access to analysis services only to database administrators like we do in SQL server. ...

SQL how to cut off string

I have column of strings with a ctiy state and number in each. SPOKANE, WA 232/107 LAS VEGAS, NV 232/117 PORTLAND, OR 232/128 Theres many more than just that but I am wondering how either I could cut off the numbers in this column and jsut show the city and state or even better cut off the numbers and make c...

TSQL 2008 Using LTrim(RTrim and still have spaces in the data

I have data I cleaning up in an old data table prior to moving it to a new one. One of the fields has spaces in the column, right & left. I wrote the following code to address this and still have leading spaces?? The bulk of the data is clean when using this code but for some reason there are spaces prior to RT addresses... Has anyone ...

nested query vs jOINs

whos could be much efficient if I use nestted subquery, JOINs Or maybe temp tables .. another question : in subqueries if i use IN Clause twice with the same query it should be execute a twice too !? like this : Select ... From X Where Exists( Select 1 From Y Where Idx = Y.SomeColumn ) Or Exists( Select 1 From Y Idy = Y.SomeColumn ...

Combining multiple rows into one row

Hello everyone. I have a table containing user-account permissions and I'm trying to write a query to return one row for each user-account combination. Here is what I have. CltKey AcctKey TranTypeID Access 10 2499 10 0 10 2499 11 1 10 2499 12 1 10 2764 10 1 10 ...

How do I limit a LEFT JOIN to the 1st result in SQL Server?

Hello, I have a bit of SQL that is almost doing what I want it to do. I'm working with three tables, a Users, UserPhoneNumbers and UserPhoneNumberTypes. I'm trying to get a list of users with their phone numbers for an export. The database itself is old and has some integrity issues. My issue is that there should only ever be 1 type of...

Unique constraint within a group of records where some value is the same

DBMS: MS Sql Server 2005, Standard I'd like to make a table constraint to have only one record have a particular value within a subset of the table (where the rows share a value in a particular column). Is this possible? Example: I have records in myTable which have a non-unique foreign key (fk1), and a bit column called isPrimary to ...

How do I get a non-null SCOPE_IDENTITY when using INSTEAD OF triggers in SQL Server 2008?

Possible Duplicate: Instead of trigger in SQL Server - looses SCOPE_IDENTITY? On SQL Server 2008, I have an INSTEAD OF trigger on a view. The SCOPE_IDENTITY() after the trigger is results in null. This causes problems with the libraries we're using. How can I control SCOPE_IDENTITY from within my trigger? This is absolutely n...

SQL 2008 - resultset order issue

We are using SQL Server 2008. We have a table called response which has a primary key called response_id. It also has a column called bid_id. When we execute the query ‘select * from response where bid_id = x’ without an ‘order by’ we are getting results in mostly ascending order (default), but once in a while in descending order (ve...

How Can I deduct Percentage from amount

Hi I have a situation where given a Column "TotalDue" and a Percentage(17,5%)Could be anything.I need to deduct the percentage and put results in a table CREATE TABLE #ResultTable (NettAmount money, GrossAmount money) For example sake lets take AdventureWorks database they have a totalDue Column on SELECT TotalDue from Sales.SalesOrd...

Replace SQLite with SQL Server?

Hi everyone. Does anyone know if it's good solution to use SQLite in multi-thread environment. I want to replace SQL Server with more simple and built-in database as there is no need to feed such big server DB. The supposed max size of DB would be 4 gigabyte after 4-5 years of usage. Is it normal for built-in DB? Could it affect performa...

Cannot connect to MDF file using VS 2008 Server explorer

Hi, as mentioned in title. Another details: file is in on my hard drive in App_Data directory I have Microsoft SQL Server 2005 on my localhost installed (full, not Express edition) When I try to connect to file using Server explorer Microsoft SQL Server Database File I get an error: network-related or instance-specific error occ...