logo
down
shadow

Checking data in one column in a temp table to a column in another table


Checking data in one column in a temp table to a column in another table

By : Streggy
Date : November 17 2020, 11:55 AM
seems to work fine I have a column in a temp table, that contains different values for each row. I want to check to make sure the values in that column exist in any row in a different table. If they do not, RaisError is called. I can do this if there is only 1 row in the temp table. However, if there is two or more, I am getting: , Just noticed my query was bad.. problem solved.
code :
IF EXISTS (SELECT tmp.[SomeRefNumber] FROM dbo.TmpTable as tmp where tmp.[SomeRefNumber] NOT IN (SELECT SOURCE.SameRefDiffTable FROM SOURCE))
BEGIN
    RAISERROR('Oh no reference doesn't exist ', 16, 1) WITH NOWAIT
END


Share : facebook icon twitter icon
Create temp table with column names from another tables column data

Create temp table with column names from another tables column data


By : user3762886
Date : March 29 2020, 07:55 AM
seems to work fine Don't think its possible to return data the way I would like so ended up doing doing it with 2 DataTables.
Create Table Variable (or Temp Table) from an existing Table but with an Extra Column

Create Table Variable (or Temp Table) from an existing Table but with an Extra Column


By : Shawn
Date : March 29 2020, 07:55 AM
This might help you I want to create a table variable or temporary table, using data from another table but with an extra column. , Its simpler
code :
SELECT *, cast('hbkkj' as nvarchar(100)) as New_Column
INTO #TempTable
FROM Existing_Table
WHERE Section = 2
How to insert data from single column of a temp table into multiple columns of main table?

How to insert data from single column of a temp table into multiple columns of main table?


By : alimad2
Date : March 29 2020, 07:55 AM
Does that help I have a data like showed below in temp table: , Try this:
code :
INSERT INTO [dbo].[t_Act]
SELECT MAX(CASE WHEN D.RN=1 THEN D.Col END)[EventType]
    ,MAX(CASE WHEN D.RN=2 THEN D.Col END) [ClientMsgID]
    ,MAX(CASE WHEN D.RN=3 THEN D.Col END) [SessionID]
    ,MAX(CASE WHEN D.RN=4 THEN D.Col END) [Protocol]
    ,MAX(CASE WHEN D.RN=5 THEN D.Col END) [MessageType]
    ,MAX(CASE WHEN D.RN=6 THEN D.Col END) [SequenceNumber]
FROM(
    SELECT *
        ,ROW_NUMBER() OVER(ORDER BY (SELECT NULL))RN 
    FROM #TempTable
    )D
ROW_NUMBER() OVER(ORDER BY OrderColumn)RN
ROW_NUMBER() OVER(ORDER BY (SELECT NULL))RN
Adding column with default values to temp table when using two stored procedures to populate the temp table

Adding column with default values to temp table when using two stored procedures to populate the temp table


By : user3184038
Date : March 29 2020, 07:55 AM
I wish this helpful for you I have a stored procedure that executes two stored procedures and gets the correct data, but now I need to add a column into the temp table with default values. , create the temp table with the new column with default value as 2
code :
CREATE TABLE #tmp
(
    ID   INT IDENTITY(1,1) , 
    CODE nvarchar(50), 
    Description nvarchar(50),
    LocationType INT default 2
)
INSERT INTO #tmp (CODE, Description)
EXECUTE dbo.uspStockAdjustmentWorkCentreSelectAll 
UPDATE #tmp
SET    LocationType  = 1

INSERT INTO #tmp (CODE, Description)   
EXECUTE dbo.uspStockAdjustmentGetSAPStorageType
insert data in physical table from temp table with less column

insert data in physical table from temp table with less column


By : Maxim Lobanov
Date : March 29 2020, 07:55 AM
may help you . I have one issue, I'm not too sure is it possible by anyway or not.
Related Posts Related Posts :
  • FreeTDS working, but ODBC cannot connect
  • How to change datetime format of varchar datatype column
  • Trigger on extended properties? SQL SERVER
  • Database Schema guidance for an app store
  • sql trigger to update based on specific column is updated and if value is equal to 'x'
  • How to descope a local variable in t-sql
  • SQL Server Compact stored procedure with multiple values in 1 input
  • How to validate the ICCID number of a SIM card in TSQL?
  • how to calculate all previous datas sum of a sql column on a date range report
  • How to create view listing all friendship for "friend1,friend2" table in T-SQL and prevent inserting duplicate
  • Sum of multiple column in SQL Server
  • Check month and day lies between two dates
  • How would I configure Effort Testing Tool to mock Entity Framework's DbContext withOut the actual SQL Server Database up
  • While looping through a function, Error: Maximum stored procedure, function, trigger, or view nesting level exceeded (li
  • Collapsing records with adjacent start and end dates
  • SQL Server Management Studio 2008 - Timeout Expired error
  • Insert date from VB to SQL Server
  • How to find what table foreign key is from?
  • Sql Server Nested Inserts possible
  • Deterministic way of getting WeekEnding (Sun) for given date column (for use in computed column)
  • SQL Server, why does one order by query work with a string, but not with an integer?
  • How do I install a SQL Server on the hosted build agent in Visual Studio Online?
  • EXECUTE AS/REVERT within a transaction in SQL Server
  • Distinct 2 field AS one column SQL SERVER
  • how to create a new database after a trigger fired from a table
  • How to sort string alphabetically
  • What's wrong with my IF/ELSE? "ELSE: Incorrect syntax near 'ELSE'."
  • CASE CLAUSE IN WHERE CONDITION
  • TSQL - Creating a running total of a column
  • Why am I getting not null here?
  • Why does sp_refreshview raise an exception on views that are not schema bound?
  • EXEC parameters from a SELECT
  • SQL Server Compact connection
  • Star Schema Structure - To many Dimensions
  • sort utf string in sql server with join clause
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org