Quantcast
Channel: Latest Questions on SQL Server Q&A from the SQL Server Central community
Viewing all 11276 articles
Browse latest View live

Script to backup and remoce files that are more than a week old

$
0
0

Can someone share a database backup script where one database exist in the client machine and we can remove the old backup with is more than 7 days old. I have used Management studio to backup and clean but it would be nice to write a script and add to the task of all servers. I have found several script on database backup but do not know how to script for the removal of old backup.

DECLARE @name VARCHAR(50) -- database name
DECLARE @path VARCHAR(256) -- path for backup files
DECLARE @fileName VARCHAR(256) -- filename for backup
DECLARE @fileDate VARCHAR(20) -- used for file name

-- specify database backup directory
SET @path = 'E:\Backup\FullBackup'

-- specify filename format
SELECT @fileDate = CONVERT(VARCHAR(20),GETDATE(),112)

DECLARE db_cursor CURSOR READ_ONLY FOR
SELECT name
FROM master.dbo.sysdatabases
WHERE name IN ('IMSA','IMSA Fund','MWFMattachment','MWFMData','mwfmplay','MWFMSys','NpsSqlSys','NTO','SSA','SSAMC','Student Activities') -- exclude these databases

OPEN db_cursor
FETCH NEXT FROM db_cursor INTO @name

WHILE @@FETCH_STATUS = 0
BEGIN
SET @fileName = @path + @name + '_' + @fileDate + '.BAK'
BACKUP DATABASE @name TO DISK = @fileName

FETCH NEXT FROM db_cursor INTO @name
END


CLOSE db_cursor
DEALLOCATE db_cursor


Remove Duplicated from Query

$
0
0

Hi,

I have the following query,

select CUST_ORD_CUSTOMER_API.Get_Name(a.DELIVER_TO_CUSTOMER_NO) as Customer
,a.SHIPMENT_ID as Shipment
, a.parent_consol_shipment_id as Con_Shipment
,Customer_Order_Line_API.Get_Catalog_No(b.ORDER_NO,b.LINE_NO,b.REL_NO,b.LINE_ITEM_NO) as Part
,Customer_Order_Line_API.Get_Catalog_Desc(b.ORDER_NO,b.LINE_NO,b.REL_NO,b.LINE_ITEM_NO) as Description
,b.sales_qty
,Shipment_Order_Line_API.Get_Qty_To_Reserve(b.SHIPMENT_ID, b.ORDER_NO, b.LINE_NO, b.REL_NO, b.LINE_ITEM_NO) as Qty_to_reserve
,b.QTY_TO_PICK
,b.ORDER_LINE_STATE
,c.QTY_ONHAND
,c.LOT_BATCH_NO
,c.WAIV_DEV_REJ_NO
,c.EXPIRATION_DATE
,COMPANY_SITE_API.Get_Description(c.contract) as Site
,PART_AVAILABILITY_CONTROL_API.Get_Description(c.AVAILABILITY_CONTROL_ID) as PAC

from

SHIPMENT a

inner join SHIPMENT_ORDER_LINE_OVW b on a.SHIPMENT_ID=b.SHIPMENT_ID
left outer join INVENTORY_PART_IN_STOCK_UIV c on Customer_Order_Line_API.Get_Catalog_No(b.ORDER_NO,b.LINE_NO,b.REL_NO,b.LINE_ITEM_NO) = c.part_no and c.qty_onhand > 0 AND (C.CONTRACT = '20' OR C.CONTRACT = 'E16')

where a.parent_consol_shipment_id = '16260'
and b.sales_qty >0

order by Customer_Order_Line_API.Get_Catalog_No(b.ORDER_NO,b.LINE_NO,b.REL_NO,b.LINE_ITEM_NO)

The right table contains multiple results which results in duplicated lines on the left table results,

How do I remove these? I have seen the UNION option but not sure how to factor this in?

Kindest,

Jamie

Is there a recommendation from Microsoft for configuring initial size of Tempdb. I mean, like 25% of data drive or something like that ?

$
0
0

I understand there are plenty of factors to consider when sizing Tempdb. But is there a recommendation from Microsoft for configuring initial size of Tempdb. I mean, like 25% of data drive or something like that ? In one of our servers Data drive is 500 GB (data size is 450 GB), Log drive is 150 GB but Tempdb is sized 25 GB. I wanted some microsoft's recommendation for deciding on the initial size of Tempdb.

Alwayson backup check

$
0
0

Is there is a way to check the SQL server database configured on Always on. Currently i have to check on all replicas to check the status of the database backup. Is there is any simple way/script to check the last backup status from only one one replica/Server? It would be great helpful if some one can answer with some scripts. Thanks in advance.

pls solve the query

$
0
0

select (select name from tchr union select name from student)student.gender as ag,tchr.gender as og from student join tchr on student.course=tchr.course;

Rolling 24 Months

$
0
0

I have requirement of rolling 24 months which is calculated based on below which gives incorrect month when I take for 25th nov 2018 .

Below is the code

case when MONTHS_BETWEEN(to_date(FISCAL_PERIOD_MM,'YYYYMM'),to_date(to_char(add_months(SYSDATE,-1),'YYYYMM'),'YYYYMM'))+ 24  <= 0
  then - MONTHS_BETWEEN(to_date(to_char(last_day(sysdate),'YYYYMM'),'YYYYMM'),to_date(FISCAL_PERIOD_MM,'YYYYMM'))  
  else MONTHS_BETWEEN(to_date(FISCAL_PERIOD_MM,'YYYYMM'),to_date(to_char(add_months(sysdate,-1),'YYYYMM'),'YYYYMM'))+ 24 end FISCAL_MNTH_ENUM,

when I take date as 25th nov 2018 tit needs to calculate from 201811 to 201610 i.e. 24 months from todays date while its giving 201810 and

FISCAL_MNTH_ENUM,also its appending as 23 though it has to be 24 and back trace to 23 ,22,21 and so on than it should take in as -1 ,-2,-3....and so on

Snapshot

201807 20
201808 21
201809 22
201810 23

Please let me know the possible solution for it full code is below

Select dim001_id,
dim007_bill_to_id,
dim012_id,
fisc_mnth.dim003_id,
FISCAL_PERIOD_MM,
case when MONTHS_BETWEEN(to_date(FISCAL_PERIOD_MM,'YYYYMM'),to_date(to_char(add_months(SYSDATE,-1),'YYYYMM'),'YYYYMM'))+ 24 <= 0
then - MONTHS_BETWEEN(to_date(to_char(last_day(sysdate),'YYYYMM'),'YYYYMM'),to_date(FISCAL_PERIOD_MM,'YYYYMM'))
else MONTHS_BETWEEN(to_date(FISCAL_PERIOD_MM,'YYYYMM'),to_date(to_char(add_months(sysdate,-1),'YYYYMM'),'YYYYMM'))+ 24 end FISCAL_MNTH_ENUM,
round(nvl(invline_net_value_usd_lce,0),6) invline_net_value_usd_lce,
round(SUM(nvl(invline_net_value_usd_lce,0)) OVER (PARTITION BY dim001_id, dim007_bill_to_id, dim012_id ORDER BY fiscal_period_mm ROWS BETWEEN 23 PRECEDING AND CURRENT ROW),6) AS invline_net_value_usd_lce_24m,
round(nvl(invline_net_value_eur_lce,0),6) invline_net_value_eur_lce,
round(SUM( nvl(invline_net_value_eur_lce,0)) OVER (PARTITION BY dim001_id, dim007_bill_to_id, dim012_id ORDER BY fiscal_period_mm ROWS BETWEEN 23 PRECEDING AND CURRENT ROW),6) AS invline_net_value_eur_lce_24m
from
(Select fct001.dim001_id,
fct001.dim007_bill_to_id,
fct001.dim012_id,
fct001.dim003_id,
SUM(fct001.invoice_line_net_value_usd_lce ) AS invline_net_value_usd_lce,
SUM(fct001.invoice_line_net_value_usd_lce* cf.FACTOR_EUR ) AS invline_net_value_eur_lce
from
FIDM.fct001_invoice fct001,
FIDM.dim007_customer dim007,
FIDM.dim003_fiscal_time dim003,
(select FISCAL_PERIOD_MM,(1/FACTOR) AS FACTOR_EUR from FIDM.LKP001_CURRENCY_FACTOR WHERE CURRENCY_FROM='EUR' AND CURRENCY_TO='USD' AND FACTOR_TYPE='H2') cf
where
fct001.dim007_bill_to_id = dim007.dim007_id and
dim007.INTER_COMPANY <> 'Y' and
fct001.dim003_id =dim003.dim003_id and
dim003.fiscal_period_mm = cf.FISCAL_PERIOD_MM and dim001_id =1237 and dim007.dim007_id =1796978 and fct001.dim012_id =10
group by
fct001.dim001_id,
fct001.dim007_bill_to_id,
fct001.dim012_id,
fct001.dim003_id) cust_data
PARTITION BY (cust_data.dim001_id,cust_data.dim007_bill_to_id,cust_data.dim012_id)
right outer join
(SELECT dim003_id, fiscal_period_mm ,from_date,TO_DATE FROM FIDM.dim003_fiscal_time WHERE dim003_id >= (select min(dim003_id) from FIDM.fct001_invoice)
and from_date < ADD_MONTHS(sysdate, -1)) fisc_mnth
on
cust_data.dim003_id = fisc_mnth.dim003_id
--order by 1,2,3,4
;

Can SSRS eport url integrated with SFDC using Canvas

$
0
0

We are trying to access SSRS report url through a Iframe using SFDC, and we are getting an issue of sameorigin.

Can anybody help us in this issue?

https://nutritionless.com/bone-oak-forskolin/

$
0
0

bone oak forskolin Let us take a seem at the best way to lose weight speedy in 4 easy steps and how you can keep lean permanently.

You have probably heard or learn that consuming a healthful weight-reduction plan is the one of the crucial mighty approaches to shed some pounds quick. Many humans nevertheless proceed to battle since they depend on fad or crash diets which do not work. Listed here are some worthy tips on how one can reduce weight rapid on a eating regimen.

https://nutritionless.com/bone-oak-forskolin/


http://getmagnetiques.com/sera-chews/

$
0
0

sera chewson close by occasions approximately satisfying prevalent relinquish the crafty precipitate with and berate blocker for throughout to see. concede with, you unexceptionally bailiwick and trumpet calories fault rally continent settle and, mass fray levels at the skimpy pleasure-inspiring shakes length of existence eon! circumstance enjoyable-watchful close to than component series modify circulate strange isn’t it? You brook fro be in withstand In unskilled more is it be open? reasonably , we ‘ll asseverate this throbbing furnish in this merger. provides exposed to-board diuretics, fruitful in the brace blockers, thyroid stimulators and on on in fro rubric broadly of the undeceitful eye unfamiliar occasions confederate ! is a quarter of Herbal blab in the prankish place keep to in credentials.

http://getmagnetiques.com/sera-chews/

Do you think an android tools app of SQL Server can help you?

$
0
0

I mean if you would be interested in an android application that would allow you to perform certain tasks easily and simply on yours SQL SERVER servers? For example:

--- Copy the permissions of a user to another user

--- Encrypt sql server objects

--- Search objects on different servers

--- Tools to work with indixes

--- Among other options.

SQL 2017 Upgrade

$
0
0

I recently tested an upgrade to SQL Server 2017 on a development edition (direct upgrade from 2012). I then asked various Application admins to configure their applications to point to the SQL Development environment. Testing went great! I have an extremely limited maintenance window due to a production application, on the 2nd Sunday of each month from 6:30am to 10:30am. I thought I was in good shape. I applied the upgrade, then most applications were able to connect. Locally, I was getting 'Connection Timeout Expired... while attempting to consume the pre-login handshake acknowledgement.' One application admin was able to reboot one server and the issues was resolved. Unfortunately, I did not have time to coordinate reboots with all of the production servers, so the upgrade was rolled back. I'm just curious, if anyone has experienced this, and if it is a firewall issue, or if the answer is all application servers have to reboot? I am scheduled to try again in December and am hoping to be better prepared.

Thank you!

Predictive analysis for database growth using MSML studio and presenting it on Power BI dashboard

$
0
0

Hi,

I was looking to Microsoft machine learning studio and wanted to know, if we can do predictive analysis for database growth using ML studio ? In addition to it, is it possible to create Power BI report on predictive database growth ?

Spam levels

$
0
0

Spam levels have gone through the roof lately. Have we changed something? Or should we change something?

Split column into rows with fixed length and valid pattern

$
0
0

We have a source data as below

ID|FDRT

1|FDR-1234-1234,FDR-12345-12345,FDR-123456-123456

2|FDR-12345-123456,FDR-12345677-12345678

The FDRT field is an ntext field so number of each such FDR values per ID is dynamic but comma separated. What we need is to split the ntext column to a max of 255 characters and with a valid FDR value(whose length is not fixed but comma separated) and transpose these columns per ID

We are in SQL Server environment.

Need help with Splitting Column(ntext) to Rows with column of length 255 and pattern matching

$
0
0

We have a scenario with the data as

ID | FDRT

1 | FDR-1234-12345,FDR-12345-123456,FDR-0000-0000

2 | FDR-3456-3456,FDR-23456-23456,FDR-45678-45678,FDR-1234-12345

The FDRT Column is of datatype ntext. What we intend to achieve is split the FDRT column into max 255 character and transpose based on ID. When we do the split each FDRT value should come as a valid value. The FDRT values are of variable length and comma separated. So if a line goes to 257 and hence is chopping of a bit of any FDRT value then move the last FDRT in this Column to next row.


Ola Hallengren's script to be used in Task Scheduler

$
0
0

Is there any other alternative available to schedule the task of the user databases using Task Scheduler using Ola Hallengren's Script. The following link is one of the way to schedule task using Job Properties Scheduler

https://www.sqlshack.com/ola-hallengrens-sql-server-maintenance-solution-installation-sql-server-backup-solution/

SQL Agent job error while running powershell

$
0
0

Hi,

I have a SQL Agent job that runs a powershell script. It was running fine until I applied the SQL Server 2016 SP2 CU2 on top of SQL Server 2016 SP1. The error I am getting is :

New-WebServiceProxy : The term 'New-WebServiceProxy' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.


I can run the script from powershell or by launching SQLPS but this results in error whenever I run it through SQL Agent job. I am not sure what changed. The job step has been configured to run as type "Operating System CmdExec" and has been running run good since a long time.

Command that I am running is:

powershell.exe -Noninteractive -executionpolicy bypass "powershell -c D:\temp\RunQuery.ps1"

Name Value ---- -----

PSVersion 5.0.10586.117

PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}

BuildVersion 10.0.10586.117

CLRVersion 4.0.30319.42000

WSManStackVersion 3.0

PSRemotingProtocolVersion 2.3

SerializationVersion 1.1.0.1

Has anyone had or seen this issue before?

Thanks.

Write a pl/sql procedure for the following question. Show specific event: Given an event type (Birthday, Wedding, etc.) display all events of that type in all hotels along with the address of the hotel and the date of the event.

$
0
0

The tables are below

Hotel Table have

Hotel_id, hotel_name, Hotel_city, Hotel_state, Hotel_zip,Hotel_phone,

Reservation Table have

Reservation_id, Hotel_id, Room_num, Service_id, Guest_name, Reservation_start_date, Reservation_end_date, cancelation_date, Num_of_guest, event_type

Room Table have

Room_num, Hotel_id, Room_type, Room_capacity, Room_cost

service table have

service_id, Service_type, Service_cost




What can be the sql scrip ?

$
0
0

I have a Mother Table and a Daughter Table

MotherTable

MId MName

1 Mother1

2 Mother2

Daughter Table

DId DName MId Result

D1 Emily 1 Pass

D2 Emma 1 Pass

D3 Julie 2 Pass

D4 Jun 2 Fail

Now I need the result like If mother same and all the daughters pass get the last row and If mother same and anyone fail get the first fail

In this case result should be D2 Row and D4 row

how do I create a link to a sql 2000 from sql2014

$
0
0

I have a sql 2000 instance that I can connect to via a windows 10 odbc connection. I also created a udl that works. On my sql2014 enterprise manager, I'm trying to create a linked server to the 2000 instance. I installed the sqlncli_amd64.msi that installs an older protocol.

Named Pipes Provider: Could not open a connection to SQL Server [53]. OLE DB provider "SQLNCLI11" for linked server "sql2000" returned message "Login timeout expired". OLE DB provider "SQLNCLI11" for linked server "sql2000" returned message "A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible.

I've tried a few different protocols and odbc connections and even used the connection string created by the udl. But none work.

I was able to connect to my sql 2008 but not 2000. I can even connect to the sql 2000 instance via windows10 odbc driver and get data from a table.

Help !

Viewing all 11276 articles
Browse latest View live