13

How to insert the value selected in the insert statement into the sql server

 3 years ago
source link: https://www.codesd.com/item/how-to-insert-the-value-selected-in-the-insert-statement-into-the-sql-server.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

How to insert the value selected in the insert statement into the sql server

advertisements

i need to insert 4 column in sql table

fist 2 column i have type remain 2 column i have to get it from another table ..how combine and insert this in single query


You can combine an INSERT with a SELECT statement, passing your values in the select statement.

Assuming you pass the values of the first two columns using parameters @a and @b you can write

INSERT INTO TABLE Table1 (Table1Col1, Table1Col2, Table1Col3, Table1Col4)
SELECT @a, @b, Table2Col1,Table2Col2
FROM Table2
WHERE ....

Related Articles

How to insert information into a SQL Server database with C #?

I'm creating a form program that allows me to insert information about mail(physical), that is received in a Department. I'm a beginner and I'm having problems with the code. I use this code: conn = new SqlConnection(conexionString); conn.Open(); com

The fastest way to insert data into a Sql Server database using C # .net

I' d like to know what is the fastest way to insert data into an Sql Server Database. Currently I' m using SqlCommand with "INSERT" command, but it takes a lot of time, cause I have to insert a lot of rows like 500k. Could you suggest me what it

Execute two insert statements in a SQL Server stored procedure?

I am trying to implement two insert statements in one SQL Server stored procedure. I did something like this, but the second insert statement does not work. Any ideas? Thanks. SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[I

How to design the SQL Server index to avoid fragmentation of columns that behave like partitions?

Consider the SQL Server table created by this command: create table Foo ( Id identity(1, 1) primary key clustered, Time datetime2, Host varchar(64), Client varchar(64), ... Bunch of columns ... ); create nonclustered index ix_foo_time on foo (time);

How to connect the sql server when it refuses to connect to Windows authentication?

I had SQL Server 2008 R2 that it was in Windows Authentication mode. but recently I can not connect ! . does any services of SQL Server disabled ? or any feature ? What should I do ? The sql server services are running. What I have done: I execute th

How to use the SQL Server Pivot on multiple columns

I have the folowing table format/ data which am trying to transpose using the SQL Server Pivot statement. Cant get it despite Googling for the last 24hrs. This is what I have in the table: --------- ------ ------- ------- ------- Product Brand Region

How to install the SQL Server Management Studio 2008 component only

Below is a list of the SQL components that I installed in the Visual Studio 2010 Professional setup. Sadly, while trying to work I could not find SQL Server Management Studio 2008. Is there a way to download SQL Server Management Studio 2008 separate

How to insert data into an SQL data table via a stored procedure

I want to insert data from a dataset in asp.net into a SQL Server table. But I can't pass the values from dataset to my stored procedure plz help me Here is my code private static SqlCommand WriteDatabase(SqlConnection conn) { SqlCommand cmd = new Sq

ASP.NET, VB.NET Can not Insert Data into a SQL Server Database

I have been troubleshooting this for a week. I try to insert a value into a SQL Server database. It doesn't show any error but when I check the database, there's no data inserted. I might doing something that is wrong here but I can't find it. Thanks

Can not insert data into MS SQL Server using PHP in IIS

As I am new to PHP, I want to insert PHP form data that will run on IIS Server than WAMP/XAMP Server, into MS SQL Server. I have installed all the necessary drivers for PHP to connect MS SQL Server. The following is the simple code I tried. I am able

How to query the SQL Server function using the sort order

I have a select statement that gives different results when querying same function from 2 databases but with same information. See below: use DB1 SELECT * FROM fn_transaction('','',null) results: ALBGU = 24.20,ALFGU = 4.00,DABGU = 24.20,JPBGU = 8.80,

How to troubleshoot the sql server performance issue

Ok this general problem has reared its ugly head twice in the past 6 months (different stored procedure). We have our internal users report a timeout error in the application. We can reproduce the problem in the application in a controlled environmen

How to search the sql server database for the string?

I know it's possible, but don't know how. I need to search Microsoft SQL database for all mentions of specific string. For example: I would like to search all tables, views, functions, stored procedures, ... for string "tblEmployes". (Not data w

How to call the SQL Server stored procedure Web service

I would like to know how to use a web service from a SQL Server stored procedure. I have a table in which the columns specify the city and state of the user. I want to pass this address as a parameter to Google Geocoding API web service and get the l

How to check the SQL Server 2008 script will work correctly on SQL Server 2005

Is there a way (a tool) to check that a SQL Server 2008 script will run on SQL Server 2005?Open up SQL Management studio, rt mouse click on the database name, select properties, select option, set compatability level. Test. A far as is known, when th

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK