tsql

T-SQL Delete Inserted Records

与世无争的帅哥 提交于 2020-02-01 04:17:25
问题 I know the title may seem strange but this is what I want to do: I have table with many records. I want to get some of this records and insert them in other table. Something like this: INSERT INTO TableNew SELECT * FROM TableOld WHERE ... The tricky part is that I want this rows that I have inserted to be deleted form the origin table as well. Is there a easy way to do this, because the only think that I have managed to do is to use a temporary table for saving the selected records and then

Getting offset of datetimeoffset in SQL Server

会有一股神秘感。 提交于 2020-01-31 22:19:39
问题 In SQL Server I need to find the offset of a given datetimeoffset(7) . I have researched the documentation and there are all ways to change the offset but not a way to know the offset of a particular value (sorry if I missed it). Well I came up with the following piece of code that I find too complicated although seems to work. DECLARE @datetimeOffset datetimeoffset(7) SET @datetimeOffset = CAST('2007-05-08 22:35:29.1234567-05:00' AS datetimeoffset(7)) DECLARE @result datetimeoffset(7)

Getting offset of datetimeoffset in SQL Server

一个人想着一个人 提交于 2020-01-31 22:19:18
问题 In SQL Server I need to find the offset of a given datetimeoffset(7) . I have researched the documentation and there are all ways to change the offset but not a way to know the offset of a particular value (sorry if I missed it). Well I came up with the following piece of code that I find too complicated although seems to work. DECLARE @datetimeOffset datetimeoffset(7) SET @datetimeOffset = CAST('2007-05-08 22:35:29.1234567-05:00' AS datetimeoffset(7)) DECLARE @result datetimeoffset(7)

How to get column-level dependencies in a view

北城余情 提交于 2020-01-31 06:19:46
问题 I've made some research on the matter but don't have solution yet. What I want to get is column-level dependencies in a view. So, let's say we have a table like this create table TEST( first_name varchar(10), last_name varchar(10), street varchar(10), number int ) and a view like this: create view vTEST as select first_name + ' ' + last_name as [name], street + ' ' + cast(number as varchar(max)) as [address] from dbo.TEST What I'd like is to get result like this: column_name depends_on_column

How to get column-level dependencies in a view

不想你离开。 提交于 2020-01-31 06:18:53
问题 I've made some research on the matter but don't have solution yet. What I want to get is column-level dependencies in a view. So, let's say we have a table like this create table TEST( first_name varchar(10), last_name varchar(10), street varchar(10), number int ) and a view like this: create view vTEST as select first_name + ' ' + last_name as [name], street + ' ' + cast(number as varchar(max)) as [address] from dbo.TEST What I'd like is to get result like this: column_name depends_on_column

How to get column-level dependencies in a view

久未见 提交于 2020-01-31 06:18:26
问题 I've made some research on the matter but don't have solution yet. What I want to get is column-level dependencies in a view. So, let's say we have a table like this create table TEST( first_name varchar(10), last_name varchar(10), street varchar(10), number int ) and a view like this: create view vTEST as select first_name + ' ' + last_name as [name], street + ' ' + cast(number as varchar(max)) as [address] from dbo.TEST What I'd like is to get result like this: column_name depends_on_column

SQL / Windows OS releasing unused space

一曲冷凌霜 提交于 2020-01-30 12:27:05
问题 I have recently done some archiving of my data, and performed the following: I had a database table that had over 33 million records, many of which were duplicates. I backed up the table and inserted the unique data into a new table, then renamed/swapped the table names, this achieved what I needed. Now however I am left with two tables... Table1 (good/live table) - 10 million records Table1_Backup (backup table) - 33 million records After doing this my SQL mdf/data file has rose to 319.7 GB,

How Do I collapse rows on null values in t-sql?

 ̄綄美尐妖づ 提交于 2020-01-30 08:29:31
问题 I'm in a weird situation with my query. My objective is to display the total deposits and withdrawals from multiple transactions for each person and display them. I am getting multiple rows that I need to collapse into one. This all needs to happen in one query SELECT lastname, firsname, case when upper(category) = 'W' then sum(abs(principal)) end as Withdrawal, case when upper(category) = 'D' then sum(abs(principal)) end as Deposit, description FROM table1 JOIN table2 ON table1.id = table2

How to select a max row for each group in SQL

﹥>﹥吖頭↗ 提交于 2020-01-30 04:35:10
问题 I want select countries with maximum value of 'Value' for a 'grpid'. Also already selected 'Country' should not be considered for other 'grpid' while checking the maximum. ( ie Country or grpid should not be repeated in the result ) SQL Fiddle Result: Country grpid Value Row_number US 49707 604456458 1 GB 5086 497654945 4 CA 909 353500201 10 JP 231 198291290 15 回答1: try this query instead, WITH OrderedOrders AS ( SELECT country,grpid,value,ROW_NUMBER() OVER(PARTITION BY country ORDER BY

android sqlite check if inserted new value

泄露秘密 提交于 2020-01-29 06:49:04
问题 I'm working with sqlite. I successfully created database and table. I also wrote code which can insert new values in my table. My code is working perfect, but now I want to show for example: toast message if inserted new value, else show error message in toast or something else. This is a my insert to table source code: public void InsertToPhysicalPersonTable(String FirstName, String LastName, String FullName, String FatherName) { try { ContentValues newValues = new ContentValues(); newValues