How to insert multiple selected row values from other table to new table

from one Query is it possible to do? To insert Multiple selected row information from one table to other table like: Customers (register_no,CustomerName, City, Country) Suppliers(register_no,SupplierName, City, Country) INSERT INTO Customers (register_no,CustomerName, City, Country) SELECT register_no SupplierName, City, Country FROM Suppliers where register_no=10; But in one time is it possible to select register_no=1,register_no=3,register_no=10; in one […]

Delete one row from same rows

I have a table T with (first, second) columns. I have two rows with first=1 and second=2. I would like to delete just one of the rows. How do I do that?

sql server: create table taking forever!

i am doing this: CREATE TABLE person ( num INT NOT NULL , firstname VARCHAR(20) NULL , lastname VARCHAR(30) NULL ); sql server is just saying “debbuging” and it’s not doing anything is there a problem with the syntax or what?

SQL query select max min value from resultset query

I’ve got a stored procedure with a query: SELECT ID ,AmountInCurrency ,ExtractionDate FROM Table This query returns 2 rows: ID AmountInCurrency ExtractionDate 1 8.00 2013-10-17 10:00:00.000 1 10.50 2013-09-16 09:00:00.000 I want to select the Min and Max Extrationdate into variables @mindate and @maxdate. Right now I put the resultset into a temp table and […]

Simple functions in queries

I need to return all the entries in my database that are fairly close to a given point. At the moment I am doing this (in the WHERE section): OR ( (Addresses.Latitude IS NOT NULL) AND (Addresses.Longitude IS NOT NULL) AND ( Abs(Addresses.Latitude – @SearchInLat) < 0.5) AND ( Abs(Addresses.Longitude – @SearchInLng) < 0.5) ) […]

Order By clause not sorting properly

This is one of the most interesting issue that I have come across in quiet some time. I have a scalar function defined in SQL server 2008 which whose return type is varchar(max) This is the query: Select dbo.GetJurisdictionsSubscribed(u.UserID) as ‘Jurisdiction’ From Users u ORDER BY Jurisdiction desc Could anybody explain why would AAAA… 2nd […]

T-SQL syntax to show both negative values and NULL values as 0

I am using SQL Server 2014 and I have a query with this line of code: ISNULL(b.[LEISURE],0) AS ‘LEISURE’ The value of Leisure can also be negative, in which case I want the value to also show as 0. How do I wrap both conditions in my code?

How to pass rows of values into SQL Server stored procedure?

I would like to insert a range of values into a pair of SQL tables, with data requiring some pre-processing (like attaching a common time stamp and some revamp of the data in both tables). Ideally I prefer to shield my code from direct SQL statements, opting to use stored procedures instead. How could I […]

Trying to create GRANT permission script

Im trying to create a GRANT script for a DB. The DB cannot use any built in roles, so I need to re-create db_reader, db_writer and EXEC for stored procedures into a GRANT script assigned to this service account. I am trying to automate this, instead of looking at each item in the DB and […]

How can I find odd house numbers in MS SQL?

The problem is I need to ignore the stray Letters in the numbers: e.g. 19A or B417

MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.