sql-server

sql find duplicate entry and insert into new column

I have a table with columns: Date, Phone, Name, and Event I need a query that will first recognize the duplicate phone entry, and then assign the name of whichever one has the earlier date to the event column. ...

how to solve parameter in sp_executesql

Hi, I have the following query: create proc [dbo].GetCustById as DECLARE @sql nvarchar(500) DECLARE @Param nvarchar(200) SET @sql = 'select @columnName from customer where custId = @custId' SET @Param = N'@columnName varchar(10), @custId int' EXEC sp_executesql @sql, @Param , @columnName = 'Address1', @custId = '42' But it always r...

Returning a boolean from a T-SQL Stored Procedure..

What's the most efficient way to return a boolean (true/false) out of a T-SQL Stored Procedure? I want it to do a query and return whether it succeeded or not. I'm calling via ASP. Let me be a little more specific about what I'm doing. If a record exists in a table (indicating a document is already reserved and can't be checked out), I...

Why is my SQL database marked readonly?

hi, i usually have my database updated in my development machine. I need to transfer it to the client using some media like cd, dvd, pendrive or other. When the client copies it and attaches it in his computer it shows readonly format and no transaction is allowed. I don't know what i am missing to make it work? Steps i follow: 1.)...

How can I create foreign keys for junction table

I have Object1 and junction table and Object2. Object2 is table that has many junction tables, but can have only one junction table torefrencing to it. When table Object1 is removed, then junction table and Object2 should be removed. How can I make foreign keys in this situation? But when Object2 is removed, then only junction table shou...

SSRS counting null values

How can I count the number of null values using SSRS? The following expression is not working: = Count(IsNothing(Feilds!.FieldName.Value)) This also isn't working: = Count(Feilds!.FieldName.Value Is Nothing) ...

Report viewer control for VB.Net1.1

Good morning fellow stack overflow people, I have a question that sounds like the start of something from the daily wtf. The company that I work for is not so much sacred of new technology they just seem to let things slip, you know the type, “It worked 5/6+ years ago so I don’t see why we should change it” Despite this I have managed ...

How to Model/Document Existing Stored Procedure Flow

Hi, I started working with a GPS Tracking System, whose backend logic is almost entirely based on the execution of Stored Procedures. They were implemented on a SQL 2000 database. I received the task to document/model the existing stored procedure flow, but I don't have experience with such a task. I was used to UML, but since its focu...

SQL query: finding a gap in a primary key

Hi there How can I write a single select statement that does the following: I have an integer column in my table and i want to find the minimum available (non-used) value in that column where the value is below 1000 and also where the value does not exist in TableB Column1 Thanks ...

Cannot connect to SQL Server Management Studio

Hi guys, tearing my hair out to be honest at this stage. I have an installation of SQL Server 2008 express on my laptop. I've been trying to login to SQL Server Management Studio without success. I even did a fresh install yesterday and still no joy. On installation I selected to install the default instance with windows authenticatio...

sql server trigger

Hi, I would like to write trigger that after inserting record to table Person I would like to create new record in table Car with PersonID = newly inserter ID from table Person: Person: ID Name Car: ID PersonID //FK to Person Name thanks for any hint, bye ...

Convert string(integer) to date in SQL

I have this query at the moment SELECT year_start_1 FROM table1 But i need to convert it to date Currently it outputs just a string like this 20100731 but I want it to look like this 31/07/2010 Any ideas Thanks Jamie ...

T-SQL Reverse Pivot on every character of a string

We have a table like below in an sql server 2005 db: event_id staff_id weeks 1 1 NNNYYYYNNYYY 1 2 YYYNNNYYYNNN 2 1 YYYYYYYYNYYY This is from a piece of timetabling software and is basically saying which staff members are assigned to an event (register) and the set of weeks the...

ASP.NET query substring

I've got this field in my database year_start_1 and it is an integer field and an example of an ouput is 20100827 I'm trying to create a substring to create year, week, day and change the format to be 27/08/2010 Here's what i'm trying Dim query as String = "Select * from openquery (devbook, 'SELECT cast(year_start_1 as varchar(8)) as ...

sql server merge with multiple insert when not matched

Hi. I'm using MERGE in my query and i'm making INSERT on clause WHEN NOT MATCHED THEN, but then i would like to get the inserted row identity and make another INSERT to some other table. Query for now is: ALTER PROCEDURE [dbo].[BulkMergeOffers] @data ImportDataType READONLY AS SET NOCOUNT ON; DECLARE @cid int = 0 MERGE dbo.oferta AS ta...

How to retrieve record from SQl using Date as parameter.

in my table am storing one column(smalldatetime). i need to retreive records by giving just date- and search the column specified above. Ex: 10/6/2010 4:01:00 PM - this is the actual value in Column. And i just want to search records from table by givin today's date. ..??? ALTER PROCEDURE [dbo].[spDisplayAllOpenPrepaidSales] @pr...

SQL: Select MIN value that dosnt already exist

Hi there, In TableA I have an int column. Is it possible using only a select statement to select the minimum value in the column that DOES NOT EXIST and is greater then 0 For example if the col has the values 1,2,9 the select statement will return 3. If the col has 9,10,11 it will return 1 I can achieve this using a temp table or us...

Compare when value could be both NULL or text

Now I know you can't directly compare NULL to anything (as null is unknown) so how would I achieve the following: select * from Material as m where MtrlCode = 826 and Exposlimit <> 'compareMe' Where Exposlimit MAY be NULL or it may not be. 'compareMe' may also be NULL. Therefore how do I compare the two? Bo...

Visual Studio Data Generation and Many-to-Many

The data generation tool that comes with Visual Studio allows you to populate tables with random/patterned data. As an example, you can tell it to populate an Employees table with 50,000 rows and you can tell it to add 5 address rows to an Addresses table for each Employee row. I've got a junction table much like the permissions exampl...

Transactional And Reporting Databases - How?

When building a transactional system that has a highly normalized DB, running reporting style queries, or even queries to display data on a UI can involve several joins, which in a data heavy scenario can and usually does, impact performance. Joins are expensive. Often, the guidance espoused is that you should never run these queries of...