Transact SQL :: Generate Insert Order Script

Apr 22, 2015

I am using SQL 2012 SE. I have 2 databases say A and B with same structure and relationships. There are 65 tables in each database. A is already replicating data to database C for 35 tables. Now I need to move data from A to B which is greater than getdate()-1 everyday  for all the tables and once the move is done I need to delete this data from A. And samething the next day. Since this is for 65 tables its challenging to identify the insert order. Once the insert order is identified the delete order will be the reverse of it.

Is there a tool or any SP that could generate the insert order script? The generate scripts data only is generating the entire data and these databases are almost 400GB. So I thought of generating a schema only script and then create an empty database with it and then generate data only to identify the order of insert. But it wont generate anything since there is no data.

View 10 Replies


ADVERTISEMENT

Transact SQL :: Method To Generate Insert Statements For Data In A Table

May 30, 2013

I have a database which will be generated via script. However there are some tables with default data that need to exist on the database.I was wondering if there could be a program that could generate inserts statments for the data in a table.I know about the import / export program that comes with SQL but it doesnt have an interface that lets you copy the insert script and values into an SQL file (or does it?)

View 7 Replies View Related

Transact SQL :: Generate Insert With Column List And Select With Columnlist Statements

Oct 22, 2015

I had to enable identity_insert on a bunch of tables and I have already done that. Now I need to modify my insert into select * from statements to include column list names along with identity columns for select as well as insert statements. The DDL is same but they are both different databases.There are almost 100 tables that it needs to be modified. Is there a way we can generate scripts for insert and select for each individual table along with their column lists including the identity column?

View 7 Replies View Related

Generate A Database Script In SQL 2005 In Alphabetical Order

Nov 7, 2007

In SQL 2000, when you generated an SQL script for a database, it was logical and the tables in the script were in alphabetical order. In SQL 2005 they are all mixed up. Am I missing something?

Thanks

Peter

View 8 Replies View Related

SQL 2012 :: Generate Scripts Result In Order Of Tables And Then Stored Procedures In Server

Sep 10, 2014

I have created one table and one stored procedure for to insert/delete/update the data in that table.

So,I was trying to move the scripts from one database to another by Generating Scripts options in SQL Server.

Generating Scripts:

Object Explorer --> Databases --> Database --> Tasks --> Generate Scripts

The generated script output is in a order of stored procedure first and then table.

REQUIREMENT: My stored procedure is dependent on table. So, I need the table script first and then stored procedure.

Note: I can generate two separate scripts for table and stored procedure, But in a just curiosity to know, Is there any way, can we re order the Generate Scripts output in SQL Server.

View 6 Replies View Related

Transact SQL :: Query To Generate XML And Grouping?

Jul 29, 2015

I am trying to generate XML path from a SQL Server Table. Table Structure and sample data as below 

CREATE TABLE #OfferTransaction
( [OfferLoanAmount1] INT
,[offferid1ProgramName] VARCHAR(100)
,[Offer1LenderName] VARCHAR(100)
,[offerid1LenderNMLSID] INT

[code]....

what changes do I need in my query so that the XML looks like the one above ( DESIRED XML). Is it possible via query changes?

View 3 Replies View Related

Transact SQL :: How To Generate GO After Each Drop Statement

May 21, 2015

I have this script which generates droptable tablename.

select  top 10000 'drop table '+name, * from sys.tables (nolock) where name like '%4[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]' order by create_date

I would like to generate 'GO' after each drop statement.

View 3 Replies View Related

Transact SQL :: Generate Drop Table Statements

Oct 13, 2015

I am trying to generate a script to drop 15 tables which have dependencies across the database. Is there a script that could generate the drop stataments based on the child table first , parent table last strategy?

View 3 Replies View Related

Transact SQL :: Method To Generate Statement Using DML Triggers

Sep 29, 2015

Is there any method to get the T-SQL command/ statement using DML triggers?.

i.e. While we insert a record using INSERT Statement, is there any possible way to get the T-SQL Statement using DML trigger for AFTER INSERT.

View 4 Replies View Related

Transact SQL :: Only Generate Email If Table Contains Data?

Jul 1, 2015

I am wanting to fire-off an email with the failed jobs anytime they are deposited into a table.  My syntax fires off an email even when the table does not contain data, it just sends a blank email.  this will only generate an email if teh table contains data?  

if exists (Select from FailedJobs)
exec msdb.dbo.sp_send_dbmail
@profile_name = 'DatabaseMail'
@recipients = 'asdfasdfsdf@aafas.com'
@from_address = 'asdfasdfacasca@cc.com'
@query = 'Select * from failedjobs'
@subject = 'List Of Failed Jobs'
@attach_query_result_as_file = 1;

View 3 Replies View Related

Transact SQL :: Generate Unique Username From Data Columns

Oct 19, 2015

I am trying to achieve the below problem statement, however I am getting stuck at the looping part.

EX: We have three columns

First Name |  Last Name | Mothers Name

I want to generate the username field using above columns, so lets consider, I have following data

First Name |  Last Name | Mothers Name
a                    b                  cdef
a                    b                  cdfg
a                    b                  cdfj

Expected Usernames:

1: a.b
2: a.b.c
3. a.b.cd

Basically, it has to be FirstName.LastName.(incremental letters from MothersName until the name becomes unique)

View 4 Replies View Related

Transact SQL :: How To Generate Week Ranges From Monday To Sunday

May 28, 2015

I need to generate the week ranges like this format :

Here from date and to date would be picked up from the table but just to make you understand i have hard coded it but this is the real date which is falling inside the table. 

Note : Week should be generated from Monday to Sunday within desired date range

View 6 Replies View Related

Transact SQL :: Generate A Report Based Of Columns In Each Table

Oct 31, 2015

I have 5 different tables with same structure. Each table has an account column and another column count. I am trying to generate a report based of the columns in each table. Account is same in all tables with same account numbers but count will be different. 

Eg:

Table 1 has Account Count

Table 2 has Account Count

Table 3 has Account Count

Table 4 has Account Count

Table 5 has Account Count

I want output as: 

Account Count Account Count Account Count Account Count Account Count 

View 4 Replies View Related

Transact SQL :: How To Generate Week Ranges For A Year In 2005

Mar 22, 2011

I have to insert YEAR   WEEKNUMBER   STARTDATE   ENDDATE values to a datatable (sayweekrange), if I pass 2011 as year.

Week range starts at 2011-03-28 to 2011-04-03 (because in my database 2010 last week range ends with 2011-03-27) like this I have to generate for 52 weeks.

I want to write a stored procedure, that takes only year as parameter. with this year I have to generate week ranges and insert into my table as shown above.

How can I do this ?

View 8 Replies View Related

Transact SQL :: How To Generate Date Ranges From Given List Of Dates

Sep 10, 2015

I want generating Valid date ranges from any list of dates.

The List of Dates could be generated from the below TSQL - 

SELECT '2015-06-02' [Date] UNION ALL
SELECT '2015-06-13' UNION ALL
SELECT '2015-06-14' UNION ALL
SELECT '2015-06-15' UNION ALL
SELECT '2015-06-16' UNION ALL
SELECT '2015-06-22' UNION ALL
SELECT '2015-06-23' UNION ALL
SELECT '2015-06-24'

And the expected output should look like - 

SELECT '2015-06-02' FromDate, '2015-06-02' ToDate UNION ALL
SELECT '2015-06-13' FromDate, '2015-06-16' ToDate UNION ALL
SELECT '2015-06-22' FromDate, '2015-06-24' ToDate

View 2 Replies View Related

Transact SQL :: Write Query To Generate Customized Result?

May 24, 2015

I have a dataset which is like:

Month, Day, Location, TotalSales
Jan       1         A  100 
Jan       1         B  200 
Jan        14       A  120 
Feb        2         A  130 
Mar        5         B  150 

I want to transform the dataset using sql query into the following format:

Month, Day, LocationATotalSales, LocationBTotalSales, TotalSales
Jan       1            100                       200                          300
Jan       14           120                        0                             120
Feb       2             130                        0                             130
Mar       5                 0                     150                          150

View 2 Replies View Related

Transact SQL :: How To Generate Rows Certain Times With A Counter Column

Jul 10, 2015

How can I write it in SQL? I have a table  that column  A   has two values of   Product  and Cost...Where value of A is Product, I have to add 6 more rows, and add column b with values from 1 to 7 for each rows ( counter)Where value of A is Cost, I have to add 4  more rows, and add column b with values from 1 to 5 for each rows ( counter).

View 3 Replies View Related

Generate Insert Statements

Apr 13, 2001

I need to write some insert statements, 1 per table, ~100 tables, all having the approximante form:

Select Into TableA Select * From TableB

Except that I need explicit statements:

Select Into TableA Col1, Col2, Col3, ... ColN Values ...

The reason is that I need to preserve the current identity values (it's a replication setup scenario). I can set Identity_Insert On, but then it wants the explicit column names and values.

Is there a wizard or utility that will generate the statements for me? With
100 tables in the db, I'm not looking forward to writing it all :-)

TIA,
Arthur

PS. Given that it's Easter weekend, if you have an answer could you please e me directly? Thanks!

View 1 Replies View Related

Generate INSERT Statements...

Jan 20, 2003

Hey guys...

I just made a little proc to generate inserts for a given table. Sadly, it contains two cursors... :(

Can any of you guys come up with a way without cursors?

Here's the proc:


create proc generate_inserts @table varchar(20)
--Generate inserts for table @table
AS
declare @cols varchar(1000)
declare @col varchar(50)

set @cols=''

declare colcur
cursor for
select column_name
from information_schema.columns
where table_name=@table

open colcur

fetch next from colcur into @col

while @@fetch_status=0
begin
select @cols = @cols + ', ' + @col

fetch next from colcur into @col
end

close colcur
deallocate colcur

select @cols = substring(@cols, 3, datalength(@cols))

--select @cols

declare @sql varchar(4000)
declare @colname varchar(100),
@coltype varchar(30)

select @sql = 'select replace(''insert ' + @table + ' (' + @cols + ') '

select @sql = @sql + 'values ('''

declare ccur
cursor for
select column_name, data_type
from information_schema.columns
where table_name=@table

open ccur

fetch from ccur into @colname, @coltype

while @@fetch_status=0
begin
if @coltype in ('varchar', 'char', 'datetime')
select @sql=@sql + ''''''


select @sql=@sql + ' + coalesce(convert(varchar, ' + @colname + '), ''null'') + '

if @coltype in ('varchar', 'char', 'datetime')
select @sql=@sql + ''''''
select @sql = @sql + ''', '''

fetch from ccur into @colname, @coltype
end

close ccur
deallocate ccur

select @sql=substring(@sql, 1, datalength(@sql)-3)

select @sql=@sql + ')'', ''''''null'''''', ''null'') from ' + @table

exec (@sql)

View 20 Replies View Related

Generate Insert Script

Jul 20, 2005

does anyone know if there is a way to generate an insert script basedon the records in a table? I want to distribute the contents of acouple of tables to customers without having to use BCP or DTS.Greetings Sjaak

View 3 Replies View Related

Generate Script And Insert Data

Oct 13, 2006

I have a question regarding generating SQL script from a database.
If you use SQL Server Management Express, it lets you generate SQL
script that can be used to recreate table structure, stored procedures,
etc. But it does not include the actual data stored in the tables.

View 2 Replies View Related

How To Generate Insert Statements In SQL Manager?

May 9, 2008

I rememeber they used to have this option to generate data script for the table in SQL 2000, but I can not find it in SQL 2005.
I need to move one table from one database to another, but I need to generate SQL Insert Statements...
 

View 12 Replies View Related

Transact SQL :: Using TOP And ORDER BY

Oct 9, 2015

I have a table where on all business days per month, for different trades, a price is uploaded, so a simplified extract:

Trade   PublishingDate   Price
10       2Jan15               100
:
10       31Jan15             150
20       2Jan15               75
:
20       31Jan15             110
:

I'm trying to write a view that will:

a) Give me the average for each trade, per month.
b) Give me the average of the last 7 days, for each trade, per month.

The first one is easy:
SELECT TradeWSRate.Trade,
CASE MONTH(TradeWSRate.PublishedDate) WHEN 1 THEN 'Jan'
WHEN 2 THEN 'Feb'
WHEN 3 THEN 'Mar'
WHEN 4 THEN 'Apr'
WHEN 5 THEN 'May'

[code]...

Column "TradeWSRate.PublishedDate" is invalid in the ORDER BY clause because it is not contained in either an aggregate function or the GROUP BY clause.How can I change the above select to work?  Ideally I want to do this all in one view, and not use functions.

View 5 Replies View Related

Generate SQL Insert Statement Fro SQL Server Database

Jun 20, 2006

Good day,

I have seen in Enterprise manager there is a toll that can script the all tables in a database, but nothing that can generate the insert statements for all the rows in each table in a secified database.

Does any one know of a application, plug in, script that can generate the insert statments for all the tables in a database?

Please someone help, this is driving me insane.

Thanks

View 5 Replies View Related

T-SQL (SS2K8) :: Insert Value Generate Special Character

Mar 12, 2014

I have a web page where the user can select the language (FR, EN, BG, ...) in a drop down list.

Next to the drop down list there is a text box where user can type the some text (translation).

User can add several description

On my web page, i have a button this button collect all information create an xml file and save all in database (sql server 2008)

that's work fine for some language => FR, EN and so on

But for bulgarian (bulgare) and greece there are some problem...

Some characters when i display it in sql look like => ???s??. ? d??ta?? a?t?

The value encoded by the user is => Ένωσης. Η διάταξη αυτή

but the result after t sql xpath is => ???s??. ? d??ta?? a?t?

Here is it my sql code where you can find my temporary table and my xml file and my xpath query

declare @tblTranslation table (idDocID int, languageID varchar(10), value varchar(500))
declare @Translations XML

set @Translations = '<?xml version="1.0" ?><Items><Item><eleKey>EN</eleKey><eleValue>This is a test</eleValue></Item><Item><eleKey>FR</eleKey><eleValue>test</eleValue></Item><Item><eleKey>BG</eleKey><eleValue>Ένωσης. Η διάταξη αυτή</eleValue></Item><Item><eleKey>HR</eleKey><eleValue></eleValue></Item><Item><eleKey>RO</eleKey><eleValue></eleValue></Item></Items>'

-- 2) fill the temporary table with information from the xml file

INSERT INTO @tblTranslation(idDocID, languageID, value)
SELECT
1
, Convert(nvarchar(max), i.query('eleKey/text()')) as colKey
, Convert(nvarchar(max), i.query('eleValue/text()')) as colValue
--
FROM @translations.nodes('/Items/Item') as x(i)
SELECT * FROM @tblTranslation

View 3 Replies View Related

Generate Insert Script Of Last Inserted Record

Apr 24, 2015

How to generate insert script of last inserted record in SQL SERVER Table???.. I want use this code for log entry purpose..

View 1 Replies View Related

Script To Generate INSERT Statements On Table

Jul 20, 2005

I'd I have a problem I'd like to post CREATE TABLE and INSERT statementsthat will create my table and insert data into the table.I can use the scripting feature in Enterprise Manager to generate CREATETABLE scripts.Is there a script I can run that will generate INSERT statements so I caninclude sample data.Thanks

View 1 Replies View Related

How Can I Generate INSERT Statements From Management Studio

Aug 25, 2007

Hello All,

How are you guys doing? Hope all is well.
This is my problem...I accidentally deleted a bunch of my SQL scripts and would like to generate the INSERT statements from Management Studio. I am currently using SQLExpress. Is there a way I can accomprish my task? Kindly advise.

Thanks a bunch!
Mohammed

View 8 Replies View Related

Generate Multiple Rows For Insert From Single Row

Jan 15, 2007

Dear all,

I have a package in which, when a Cost Center has X as a value, I must insert not X but many different Y value, which are associated with X. How can I gather and treat those Y values? Only using a Script Component?

Regards,

Pedro Martins

View 1 Replies View Related

Transact SQL :: Order By Month

Apr 21, 2015

I am using below query i want to order it by month so that data is displayed like

Select (count(I.Colour)) as Litres,
DATEName(MONTH,ShipDate) as [Loaded Date] from InkData I
group by DATEName(MONTH,ShipDate)
order by DATEName(MONTH,ShipDate)

Right now it is not ordering by month, it is ordering alphabetically.I want this to be ordered like

Jan
Feb
March

View 6 Replies View Related

Transact SQL :: Order By A Column From Another Table

Sep 2, 2015

I have two tables, one is called (questions), the second one (answers).

questions columns are (ID,questionTitle)

answers columns are (ID,questionID,answer, answerDate)

I use this query to load data: "SELECT q.questionTitle,COUNT (a.ID),a.answerDate FROM questions q LEFT JOIN answers a ON q.ID=a.questionID" the query is easy, but my problem which I can't solve is how can I fetch the data ordered by the column answerDate, I mean I want the first record to be the one which has the most recent answer and so on.

View 12 Replies View Related

Transact SQL :: CASE Order Of Evaluation

Sep 24, 2015

I have the following query in a user-defined function. It accepts a single string parameter, but for the sake of simplicity, I have substituted actual strings in the query. It basically checks the passed string. If it ends with "Id", it strips off the "Id" and returns the resulting string. If it ends with "Id" followed by a digit, it strips that off and returns the string.

SELECT CASE
WHEN LEN('IncidentViolationId') > 2 AND RIGHT('IncidentViolationId', 2) = 'Id' THEN LEFT('IncidentViolationId', LEN('IncidentViolationId') - 2)
WHEN PATINDEX('%Id[0-9]', 'IncidentViolationId') > 1 THEN LEFT('IncidentViolationId', PATINDEX('%Id[0-9]', 'IncidentViolationId') - 1)
ELSE 'IncidentViolationId' END

This code has worked flawlessly for quite some time and all of a sudden I get "Invalid length parameter passed to left function". I understand why LEFT() would normally fail if I passed it a -1 for the second parameter, but in this scenario, asI understand it, it never should have reached the second WHEN condition since the first one evaluates to true. Why and why all of a sudden?

View 10 Replies View Related

Transact SQL :: Get Active Order Dollars

Sep 18, 2015

This is kind of a follow-up on my previous post "Get 15th and last day trans".  Our client has asked for open sales orders dollars for a given date range to include order dollars active as of the 15th of the month and the last day of the month. 

Below is what I started and I hard-coded the Jan15Open and JanEndOpen so you could see what I am trying to accomplish.  So, for example, if I pass @StartDate of '01-01-2013' and @EndDate of '12-31-2014' I could get back results for 01-15-2013, 01-31-2015, 02-15-2013, 02-28-2013, etc. all the way to 12-31-2014.  Note that the results will depend on the TransDate datetime column.  Once I get the query correct I plan to create a temp table to hold the results so I can report them back in a web page. 

ALTER PROCEDURE [dbo].[afa_selSalesOrdersOpen]
@StartDatedatetime = null,
@EndDatedatetime = null
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

[Code] ....

View 9 Replies View Related







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