SQL Server 2014 :: Updating A Column In One Table From Another Table

Dec 23, 2013

We have two tables with names X and Y.

X has a,b columns. And Y has c,d columns.

I want to update b column in X table with the values from d column in Y table on condition X.a=Y.c.

View 3 Replies


ADVERTISEMENT

SQL Server Admin 2014 :: Add New Column To A Table

Aug 24, 2015

I am new in SQL Server, What to check ,what action do i need to take while adding a new column to a table.

View 5 Replies View Related

SQL Server 2014 :: Show Sum Of Particular Column In Last Row Of Table

Sep 18, 2015

I have a table with some rows and columns what i want is i want to Show sum of particular column in the last row. This is my code.

SELECT DISTINCT Cluster.ClusterName, Gruppe.GruppeName, Arbeitspaket.ArbeitspaketName, BMWProjekt, AnzahlAP, Abgerechnet, InBearbeitung, Billanz FROM Bestellung
INNER JOIN Cluster ON Bestellung.Cluster = Cluster.rowid
INNER JOIN Arbeitspaket ON Bestellung.Arbeitspaket = Arbeitspaket.rowid
INNER JOIN Gruppe ON Bestellung.Gruppe = Gruppe.rowid
WHERE Projekt ="EA-284-Nxx" AND AnzahlAP <> 0 AND Abgerechnet is 1 AND InBearbeitung is NULL AND Billanz is NULL;

View 4 Replies View Related

SQL Server 2014 :: Columns List With And Without Identity Column In A Table?

Feb 24, 2015

I have the following 2 Query's - case when Table has no Identity Column and other with identity Column . I am planning to make it to single Query .

Query 1:
SELECT @ColumnNamesWhenNoIdentity = COALESCE(@ColumnNamesWhenNoIdentity + ',', '') + Name +'= SOURCE.'+Name
FROM sys.columns WITH(NOLOCK) WHERE object_id =
(
SELECT sys.objects.object_id
FROM sys.objects WITH(NOLOCK)
INNER JOIN sys.schemas WITH(NOLOCK) ON sys.objects.schema_id = sys.schemas.schema_id
WHERE sys.objects.TYPE = 'U' AND sys.objects.Name = 'Testing1' AND sys.schemas.Name ='dbo'
)

Query2:
SELECT @ColumnNamesWhenNoIdentity = COALESCE(@ColumnNamesWhenNoIdentity + ',', '') + Name +'= SOURCE.'+Name
FROM sys.columns WITH(NOLOCK) WHERE is_identity != 1 AND object_id =
(SELECT sys.objects.object_id FROM sys.objects WITH(NOLOCK)
INNER JOIN sys.schemas WITH(NOLOCK) ON sys.objects.schema_id = sys.schemas.schema_id
WHERE sys.objects.TYPE = 'U' AND sys.objects.Name = 'Testing2' AND sys.schemas.Name ='dbo'
)

View 8 Replies View Related

SQL Server 2014 :: Incrementing Number In Table And Then Resetting Column

Jul 15, 2015

I have four columns in my table, the first one is the identity column

col1 Col1 col2 col3

1 12 1 This is Test1
2 12 2 This is Test1
3 12 3 This is Test3
4 12 4 This is Test4
5 12 5 @@@@@

When, I see, @@@ sign in my col4, I need to restart the col3 from 1 again so it will look like this

col1 Col2 col3 col4

1 12 1 This is Test1
2 12 2 This is Test1
3 12 3 This is Test3
4 12 4 This is Test4
5 12 5 @@@@@
6 12 1 This is another test1
7 12 2 This is another Test2

Is it possible to do that?

View 8 Replies View Related

SQL Server 2014 :: Select Data From Table With A Particular Column Priority

Aug 1, 2015

DECLARE @Table TABLE
(minv_code INT,
alert_msg varchar(10),
alert_time Datetime)

[Code]....

i want to select the data priority wise
the o/p should look like below

first row - 873939, 'Meter', '7/24/2015 3:31:22'
second row - 873939, 'Tamper', '7/24/2015 3:30:00'
third row - 873939, 'Reverse', '7/24/2015 3:31:18'
fourth row -873940, 'Tamper', '7/24/2015 3:31:22'
fifth row - 873940, 'Reverse', '7/24/2015 3:30:00'

View 1 Replies View Related

SQL Server 2014 :: Pivot Table With Column Names To Rows?

Aug 1, 2015

I have a table with following rows.

FY REVCODE Jul Jun
2015 BNQ 1054839 2000000
2015 FNB 89032 1000000
2015 RS 1067299 3000000

I am looking to convert it to

Month BNQ FNB RS
JUL 1054839 89032 1067299
JUN 2000000 1000000 3000000

I tried with the following and result is coming for one month i.e. JUL but not with the second Month i.e Jun

SELECT 'Jul1' AS MON, [BNQ], [FNB], [RS]
FROM
(SELECT REVENUECODE, SUM(ROUND(((Jul/31)*30),0)) AS JUL
FROM RM_USERBUDGETTBL
WHERE USERNAME='rahul' AND FY=2015
GROUP BY REVENUECODE, USERNAME
) AS SourceTable
PIVOT
(SUM(JUL) FOR REVENUECODE IN ([BNQ], [FNB], [RS])) AS PivotTable

Results:

MONTHBNQ FNB RS
Jul11054839 89032 1067299

View 4 Replies View Related

SQL Server Admin 2014 :: Create Temporary Table With Dynamics Column

Jun 10, 2014

I have created a stored procedure for retrieving column name, as shown below

CM_id, CM_Name, [Transaction_Month], [Transaction_Year], [Invoice raised date],[Payment Received date],[Payout date],[Payroll lock date]

Now I am trying to create a temporary table using the above generated coluimns from Stored Procedure with datatype.

View 3 Replies View Related

Updating A Single Column On A Table SQL Server 2005 (45 Records), The Session Hangs...

May 12, 2007

Hello, I am pretty new with SQL Server 2005.

I have installed SQL Server Express Edition. I have migrated a set of tables from Oracl10g (by using Microsoft's Migration Tool Kit).While I am trying the following simple update command, the session hangs and it never finishes !!!!!!!!!!!!

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

select pos_key from pos_station where staff_key = 1105

POS_KEY
=======
NULL


update pos_station set pos_key = 1 where staff_key = 1105

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

The table has a few constraints and a couple of indices in place.

Then I create another table (but no contraints or indices), just copy the data from the problematic one and the update WORKS (in msecs) :



update pos_station_new set pos_key = 1 where staff_key = 1105

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Is there any way to tell if the table (any table in SQL Server) is corrupted or not ?

How can I tell if a session is waiting for something and what is that something ?

Thank you very much for your help.

Tom

View 7 Replies View Related

SQL Server 2014 :: How To Update Values Based On Column Into Multiple Columns In Another Table

Jul 31, 2015

I have a table #vert where I have value column. This data needs to be updated into two channel columns in #hori table based on channel number in #vert table.

CREATE TABLE #Vert (FILTER VARCHAR(3), CHANNEL TINYINT, VALUE TINYINT)
INSERT #Vert Values('ABC', 1, 22),('ABC', 2, 32),('BBC', 1, 12),('BBC', 2, 23),('CAB', 1, 33),('CAB', 2, 44) -- COMBINATION OF FILTER AND CHANNEL IS UNIQUE
CREATE TABLE #Hori (FILTER VARCHAR(3), CHANNEL1 TINYINT, CHANNEL2 TINYINT)
INSERT #Hori Values ('ABC', NULL, NULL),('BBC', NULL, NULL),('CAB', NULL, NULL) -- FILTER IS UNIQUE IN #HORI TABLE

One way to achieve this is to write two update statements. After update, the output you see is my desired output

UPDATE H
SET CHANNEL1= VALUE
FROM #Hori H JOIN #Vert V ON V.FILTER=H.FILTER
WHERE V.CHANNEL=1 -- updates only channel1
UPDATE H
SET CHANNEL2= VALUE
FROM #Hori H JOIN #Vert V ON V.FILTER=H.FILTER
WHERE V.CHANNEL=2 -- updates only channel2
SELECT * FROM #Hori -- this is desired output

my channels number grows in #vert table like 1,2,3,4...and so Channel3, Channel4....so on in #hori table. So I cannot keep writing too many update statements. One other way is to pivot #vert table and do single update into #hori table.

View 5 Replies View Related

Updating A Column In One Table From Another Table

Dec 23, 2013

We have two tables with names X and Y.

X has a,b columns. And Y has c,d columns.

I want to update b column in X table with the values from d column in Y table on condition X.a=Y.c.

View 1 Replies View Related

Updating Column In A Table

Jan 18, 2001

hi i want to update column with new value in a table is it possible to do so in stored procedure . the name of the column will be an input to stored procedure ie at the time of writing the stored procedure i dont know which column the user will be updating

View 2 Replies View Related

Updating Table With New Column

May 25, 2001

Does anyone know of the SQL statement to add additional comuns to an existing table. I know i can do it through enterprise managaer, but I want to see if I can do it from query analyzer or some script to add columns without having to recreate the table. Or a way to save off the data and recreate the table then placing data back in? I hope that makes sense. I am thinking of this from the sens of doing all updates through source safe

Thanks!

View 1 Replies View Related

SQL Server Admin 2014 :: Insert A Row To A Table Based On Table Values?

Jun 10, 2015

Here is my table:

My question is: How can I insert a row for each unique TemplateId. So let's say I have templateIds like, 2,5,6,7... For each unique templateId, how can I insert one more row?

View 0 Replies View Related

Updating A Column With A Count From Another Table?

May 18, 2014

My goal is to with one update statement, fill TABLE1.counter (currently empty) with the total count of TABLE2.e# (employee). Also, if TABLE1.e# isn't in TABLE2.e# then it sets it to "0" (TABLE1.e# 8 and 9 should have a counter of 0) This is for sqlplus.

e.g. TABLE2:

e#
--
1
2
3
4
5
5
6
7
7
1
2
3
4
5
UPDATE TABLE1
SET counter = (
SELECT COUNT(TABLE2.e#)
FROM TABLE2 INNER JOIN TABLE1 ON (TABLE2.e# = TABLE1.e#)
GROUP BY TABLE2.e#);

--^Doesn't work

so my TABLE1 should be:

e# counter
-----------
1 .. 2
2 .. 2
3 .. 2
4 .. 2
5 .. 3
6 .. 1
7 .. 2
8 .. 0
9 .. 0

(The .. is just spacing to show the table here)

View 1 Replies View Related

Updating A Table Data From Another Table Using Sql Server 2000

Jun 4, 2008

Hi All,
I have a Problem while updating one table data from another table's data using sql server 2000.
I have 2 tables named TableA(PID,SID,MinForms) , TableB(PID,SID,MinForms)
I need to update TableA with TableB's data using a single query that i have including in a stored procedure.

View 2 Replies View Related

SQL Server Admin 2014 :: Few Record Loss In Table Primary Key Where Same Records Exists In Foreign Key Table?

Jun 21, 2015

Previously same records exists in table having primary key and table having foreign key . we have faced 7 records were lost from primary key table but same record exists in foreign key table.

View 3 Replies View Related

Updating A Column In A Table That Contains 50 Million Rows

Feb 27, 2008

I'm looking for some performance assistance on updating a column value in a table that contains approximately 50 million rows. I have a permanent table in another database that has the key column and value to be set. My query is listed below, but I'm afraid it will run quite awhile. Any suggestions would be appreciated.

update mytable
set column2 = b.column2
from mytable as a
join mytable1 as b
on a.column1 = b.column1



There is a one to one relationship between the two tables.

View 8 Replies View Related

Updating Table Column With Cumulative Numbers

Nov 13, 2007

Hello,

One more question about this Custom Calendar table I'm creating. I have a column called "IsWorkdays" which indicates if the day represented by a row is a workday or not. For our purposes, I also need to create a row that accumulates those numbers by month. So, if it is the 3rd workday of the month, this column would have a 3. This is beyond my current T-SQL ability. Does anyone know how to do this?

Thanks a lot,
Andy

SQL version: 2005, Standard edition.

View 1 Replies View Related

SQL Server 2014 :: Repetition Of A Table When Joined With Another Table

Jul 29, 2014

table1

id value
1 11
2 12
3 13
4 14

table2

id1 value1
1 21
2 22
1 31
2 32

in need output as follows

id value id1 value1
1 11 1 21
2 12 2 22
3 13 null null
4 14 null null
1 11 1 31
2 12 2 32
3 13 null null
4 14 null null

View 9 Replies View Related

Updating A Column With A Column From Another Table

Apr 1, 2004

Hi, I am kinda new to this so here it goes:

table name: USERS
field names : LName, FName, EmpID


other table name:PERSONNEL
field names : (same as USERS)

The EmpID column in my USERS table is blank (I have 30 records in the table.)

I would like to update the USERS.EmpID table with the PERSONNEL.EmpID data

how would I do this or what would the code be?

sanctos

View 2 Replies View Related

SQL Server Admin 2014 :: Possible To Find Table Size And In That Table Each Row Size

Jun 10, 2014

It is possible to find table size and in that table each row size.

View 4 Replies View Related

SQL Server 2014 :: Selecting Records From Table 2 While Counting Records In Table 1

Aug 11, 2015

Table1 contains fields Groupid, UserName,Category, Dimension

Table2 contains fields Group, Name,Category, Dimension (Group and Name are not in Table1)

So basically I need to read the records in Table1 using Groupid and each time there is a Groupid then select records from Table2 where Table2.Category in (Select Catergory from Table1)
and Table2.Dimension in (Select Dimension from Table1)

In Table1 There might be 10 Groupid records all of which are different.

View 9 Replies View Related

Database Automatically Creates Xxx_Temp Table While Modifying / Updating Table Structure .

Dec 16, 2007

Hello friends,

I am new to the SQL Server 2005 development.

From last 1 week or so, i have been facing very strange problem with my sql server 2005s database
which is configured and set on the hosting web server. Right now for managing my sql server 2005 database,
i am using an web based Control Panel developed by my hosting company.

Problem i am facing is that, whenever i try to modify (i.e. add new columns) tables in the database,
it gives me error saying that,

"There is already an object named 'PK_xxx_Temp' in the database. Could not create constraint. See previous errors.
Source: .Net SqlClient Data Provider".

where xxx is the table name.

I have done quite a bit research on the problem and have also searched on the net for solution but still
the problem persist.

Thanks in advance. Any help will be appreciated.

View 5 Replies View Related

SQL Server 2012 :: Update Table From Variable Table Column?

Oct 6, 2014

I am trying to use a stored procedure to update a column in a sql table using the value from a variable table I getting errors because my syntax is not correct. I think table aliases are not allowed in UPDATE statements.

This is my statement:

UPDATE [dbo].[sessions_teams] stc
SET stc.[Talks] = fmt.found_talks_type
FROM @Find_Missing_Talks fmt
WHERE stc.sessionid IN (SELECT sessionid FROM @Find_Missing_Talks)
AND stc.coupleid IN (SELECT coupleid FROM @Find_Missing_Talks)

View 2 Replies View Related

Updating Table On Different Sql Server

Aug 9, 2002

Hi,

Here is my problem.

There are 2 different SQL Servers, SQLSvr1 and SQLSvr2(both of them are SQL Server 7.0). On SQLSvr1, I have 3 tables and 1 stored procedure and on SQLSvr2, I have 1 table.

Now, I want to know is it possible for me to update table on SQLSvr2 using a stored procedure on SQLSvr1. Assuming I have all rights and permissions on both servers.


Thanks in advance
-Dinesh

View 1 Replies View Related

Trigger For Updating Value On One Table When That Value Is Updated On Base Table

Jul 30, 2015

If the id1 will change in table1 it should also change the corresponding id1 field in table2 it does not do anything.

CREATE TRIGGER [dbo].[IDCHANGE]
ON [dbo].[table1]
AFTER UPDATE
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from

[Code] .....

View 1 Replies View Related

SQL Server 2008 :: How To Get Column From Another Table And Insert Into Other Table

May 18, 2015

I have two table 'Cal_date' and 'RPT_Invoice_Shipped'.Table cal_data has column month_no, start_date and end_date. And table RPT_Invoice_Shipped has columns Day_No, Date, Div_code, Total_Invoiced, Shipped_Value, Line_Shipped, Unit_Shipped, Transaction_Date.

I am using below insert statment to insert data in RPT_Invoice_Shipped table.

insert into [Global_Report_Staging].[dbo].[RPT_Invoice_Shipped]
(Day_No, Date, Div_code, Total_Invoiced, Transaction_Date)
select , CONVERT(DATE,Getdate()) as Date, LTRIM(RTRIM(div_Code)),
sum(tot_Net_Amt) as Total_Invoiced, (dateadd(day, -1, convert(date, getdate())))
from [Global_Report_Staging].[dbo].[STG_Shipped_Invoiced]
WHERE CONVERT(DATE,Created_date )=CONVERT(DATE,Getdate())
group by div_code

while inserting in column Day_No in RPT_Invoice_Shipped table, I have to use formula (Transaction_Date-start_date+1) where Transaction_Date from STG_Shipped_Invoiced and start_date from Cal_date table. I was using datepart (mm, Transaction_Date) so it gives month_no, and this month_no we can join with month_no of Cal_date table and fetch start_date from Cal_date table, so that we can use start_date for formula (Transaction_Date-start_date+1).

But I am getting difficulty to arrange this in above query. how to achieve this?

View 1 Replies View Related

Updating A Users Table In SQL Server

Nov 10, 2003

Hello all,

I am relatively new to this platform and am trying to update a table of user information and passwords through a series of SQL commands. We import a new file of users every two hours and I would like to have three SQL statements:

- One to add new users not currently in Users table
- One to delete users no longer in our source file
- One to update every field (but one or two) for already existing users.

Any help on creating the SQL (as well as where to store it and how to automate it) is greatly appreciated!

Thanks!

View 2 Replies View Related

Updating A Table By Both Inserting And Updating In The Data Flow

Sep 21, 2006

I am very new to SQL Server 2005. I have created a package to load data from a flat delimited file to a database table. The initial load has worked. However, in the future, I will have flat files used to update the table. Some of the records will need to be inserted and some will need to update existing rows. I am trying to do this from SSIS. However, I am very lost as to how to do this.

Any suggestions?

View 7 Replies View Related

Updating Table Referencing 2nd Table Using Case

Feb 9, 2008

Hi

Im trying to create an update statement which references two tables (join) and has a CASE clause attached. Not sure where im going wrong...

Using T-sql!!!

update import set import.gone =
from import
inner join stat
ON stat.id = import.id
CASE
WHEN stat.A = import.field2 THEN import.gone = sec.A
WHEN stat.B = import.field2 THEN import.gone = sec.B
WHEN stat.C = import.field2 THEN import.gone = sec.C
WHEN stat.D = import.field2 THEN import.gone = sec.D
WHEN stat.E = import.field2 THEN import.gone = sec.E
WHEN stat.F = import.field2 THEN import.gone = sec.F
ELSE import.gone = null
END

Any help would be greatly appreciated

View 3 Replies View Related

Updating A Table With Data From A Temp Table

Oct 19, 2007

I am trying to update a table in one database with data from a temporary table which i created in the tempdb.

I want to update field1 in the table with the tempfield1 from the #temp_table

The code looks something like this:

Use master
UPDATE [dbname].dbo.table
SET [dbname].dbo.table.field1 = [tempdb].dbo.#temp_table.tempfield1
WHERE ( [dbname].dbo.table.field2= [tempdb].dbo.#temp_table.tempfield2
AND [dbname].dbo.table.field3= [tempdb].dbo.#temp_table.tempfield3
AND [dbname].dbo.table.field4= [tempdb].dbo.#temp_table.tempfield4)

I get the following error:
Msg 4104, Level 16, State 1, Line 2
The multi-part identifier "tempdb.dbo.#temp_table.tempfield2" could not be bound.
Msg 4104, Level 16, State 1, Line 2
The multi-part identifier "tempdb.dbo.#temp_table.tempfield3" could not be bound.
Msg 4104, Level 16, State 1, Line 2
The multi-part identifier "tempdb.dbo.#temp_table.tempfield4" could not be bound.

What is wrong?

View 1 Replies View Related

Updating Columns In Sql Server Table From My Asp Web Page

Oct 1, 2007

I have a web interface where i have listing of several data and check box for inserting data into SQL server 2005 database table,
so I am able to inset data to sql tables using stored procedure. Now the question is i want to update these inserted records(agency approval column inserted as 1) in same table and assign value 1 fot the checked data to column finace approval as 1.
Here is how ia have webclas  library where i script for getting the insert parameterspublic void Process_Payment(ref DataTable TableWithPayments, string Payment)
{SqlCommand InsertCommand = new SqlCommand();
SqlConnection AccessDatabase = new SqlConnection(FinanceSourceWrite.ConnectionString);int PaymentID = 0;
AccessDatabase.Open();
InsertCommand.Connection = AccessDatabase;
 
 
//DataTable TemporaryTable = new DataTable();
//TemporaryTable = TableWithPayments;SqlTransaction TransactionProcess = null;
SqlParameter InsertParameters;foreach (DataRow DataCommentInfo in TableWithPayments.Rows)
{InsertCommand.CommandText = "InsertPaymentList"; //THIS IS my stored procedureInsertCommand.CommandType = CommandType.StoredProcedure;
TransactionProcess = AccessDatabase.BeginTransaction();
// SET ALL THE VALUES FOR THE PARAMETERSInsertParameters = InsertCommand.Parameters.Add("@JC_ID", SqlDbType.Int);
InsertParameters.Direction = ParameterDirection.Input;InsertParameters.Value = DataCommentInfo["JC_ID"];
 InsertParameters = InsertCommand.Parameters.Add("@Payment_Type", SqlDbType.Int);
InsertParameters.Direction = ParameterDirection.Input;InsertParameters.Value = DataCommentInfo["Payment_Type_ID"];
 
InsertParameters = InsertCommand.Parameters.Add("@Agency_approval", SqlDbType.Int);InsertParameters.Direction = ParameterDirection.Input;
InsertParameters.Value = DataCommentInfo["Agency_approval"];
 
Now my stored procedure
  
ALTER PROCEDURE [dbo].[InsertPaymentList](
@JC_ID int ,
@Payment_Type int,
@Payment_Group int,
@AGENCY_ID int,
@Agency_approval int,
@Agency_approval_date datetime,
@Program_ID nvarchar(50),
@Status bit,
@Jobsite_code_ID int,
@Date_Stamp datetime,
@Provider nvarchar(50),
@UserName nvarchar(256),
@Activity_ID int,
@Subproject_ID int,
@Payment_Support_Retention_List_ID int,
@WPR_ID int,
@Placement_ID int,
@Enrollment_ID int,
@Satisfaction_ID int,
@Enrollment_Bonus_ID int,
@Re_Placement_Bonus_ID int
)AS
INSERT INTO Payment_LIST_AIMS
(JC_ID, Payment_Type, Payment_Group, AGENCY_ID, Agency_approval,
Agency_approval_date, Program_ID, status,
Jobsite_code_ID, Provider, UserName, Placement_ACTV_ID, Placement_Sub_ID, Support_Retention_ID, WPR_ID, Placement_ID,Enrollment_ID,Satisfaction_ID,Enrollment_Bonus_ID,Re_Placement_Bonus_ID)
VALUES  @JC_ID, @Payment_Type, @Payment_Group, @AGENCY_ID, @Agency_approval,@Agency_approval_date, @Program_ID, @Status,
@Jobsite_code_ID, @Provider, @UserName, @Activity_ID,
@Subproject_ID, @Payment_Support_Retention_List_ID, @WPR_ID, @Placement_ID,@Enrollment_ID,@Satisfaction_ID,@Enrollment_Bonus_ID,@Re_Placement_Bonus_ID)
SELECT CAST(scope_identity() as int)
Here like you see agency approval column in SQL server table gets value assigned as 1 when Agency user clicks the confirm payment button and so all the values as above....
Now another user Finance user process the same records from the web UI and clicks the process payment button at this stage ..i need to update Finance approval column as 1 agains that particular record existing th the SQL table, there are two three coulmc to be updated , Finance approval(this is where i need help) , Finance approval date , and user
 Being a newbie please help me whith how i can fix this
Thanks
Santosh
 
 
 

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved