If I pull data from one sql server and load in next table. but I want to get source table name. How can i get source table name?
If I pull data from one sql server and load in next table. but I want to get source table name. How can i get source table name?
Building a script for reporting SQLUpdates Compliance
Hi,
I am trying to write a SQL to report SQLUpdates Compliance. I have a table which contains server information like version and build.
SQLServerUpdateReport
InstanceSQLServerBuildDateExecutedJen201412.0.5590.129/11/2018 3:01:37 AMEric201613.0.5153.029/11/2018 3:01:37 AMSam20059.00.3353.0029/11/2018 3:01:37 AMDave201211.0.7001.029/11/2018 3:01:37 AMThe view vw_SQLUpdateList gets the latest SQL Service Pack / CU and there are multiple values for some versions.
VersionProductVersion20059.00.5266.0020059.00.5000.00201211.0.7001.0201412.0.6024.0201412.0.5600.0201613.0.5233.0201613.0.5026.0What I am trying to do is to see if the Build value is greater or equal to the minimum value of the 2 values of ProductVersion, the server should be marked compliant else marked as NO.
Select UR.[Instance]
,UR.[SQLServer]
,substring(UR.[Build],1,9) as Build
,substring(SUL.ProductVersion,1,9) as [Current]
,CASE
When Exists ( Select max(ProductVersion) from [DBA].[dbo].[vw_SQLUpdateList]
where substring(UR.[Build],1,9) >= substring(ProductVersion,1,9) )
THEN 'YES' ELSE 'NO'
END as Compliant
FROM [DBA].[dbo].[SQLServerUpdateReport] UR
join [DBA].[dbo].[vw_SQLUpdateList] SUL
on SUL.[Version] = UR.SQLServer
WHERE DateExecuted > getdate()-1
group by UR.[Instance], UR.[SQLServer], UR.[Build], SUL.ProductVersion
The above SQL returns multiple rows for all instances which have multiple values for the version and is not correct. Can you help fix this and suggest a better way to implement this logic?
Thanks.
How to backup database in external drive?
We have a standalone installation of database on sqlserver 2008R2 and want ot backup the database in external drive since the size of the back up file is 18G. Used script as well as Maintenance plan and got the error, how do I grant permission so that I can store in external USB drive
Msg 3201, Level 16, State 1, Line 1 Cannot open backup device 'P:\Backups.SQL\PWNT\PWNT_backup_2018_11_29_135357_7686135.bak'. Operating system error 3(The system cannot find the path specified.). Msg 3013, Level 16, State 1, Line 1 BACKUP DATABASE is terminating abnormally.
SSIS issues previewing source data
I have SSIS packages to import data from a Oracle database. Connection to source are ok and the parsing the query reveal no issue. However, when clicking the preview button it comes the error message. Any idea what's causing that?
=================================== There was an error displaying the preview. (Microsoft Visual Studio) =================================== The system cannot find message text for message number 0x80040e51 in the message file for OraOLEDB. (OraOLEDB) ------------------------------ Program Location: at Microsoft.DataTransformationServices.Design.UnsafeNativeMethods.ICommandWithParameters.GetParameterInfo(IntPtr& pcParams, IntPtr& prgParamInfo, IntPtr& ppNamesBuffer) at Microsoft.DataTransformationServices.Design.DesignUtils.GetQueryParameters(ConnectionManager connectionManager, String sqlStatement) at Microsoft.DataTransformationServices.Design.PipelineUtils.ShowDataPreview(String sqlStatement, QueryParameter[] parameters, ConnectionManager connectionManager, Control parentWindow, IServiceProvider serviceProvider, IDTSExternalMetadataColumnCollection100 externalColumns, Int32 timeout) at Microsoft.DataTransformationServices.DataFlowUI.DataFlowConnectionPage.previewButton_Click(Object sender, EventArgs e)
Load File from Sharepoint to Sql table using SSIS
I need to load file from Sharepoint to sql db using SSIS, i found two posts with the solution there have used script task
1. https://sqlblogcasts.com/blogs/drjohn/archive/2007/11/04/downloading-excel-files-from-sharepoint-using-ssis.aspx
by using this solution getting error on the line : client.DownloadFile(fileUrl, file.FullName)
Error : Remote server return an error : Forbidden
2. https://www.codeproject.com/Questions/457161/how-to-download-files-from-Sharepoint-document-lib?tab=mostrecent
By using this solution getting error as SpSite is not reognized.
Even if i added the reference of Microsoft.sharepoint.dll
Microsoft.sharepoint.Client.dll
Can you please help me with this which solution is better,
P.S. I have access to the Sharepoint file url only and not to library.
Thanks in advance,
Pankaj
I'm getting the following error with my xml script: Msg 6809, Level 16, State 1, Line 2
SELECT( SELECT Top 2 '<?xml verion= "1.0" encoding="utf-8"?>', P.[ID] as PartNumber, P.[DESCRIPTION] as Description, CASE WHEN BX.[BOM_Level] = '0' THEN 'YES' ELSE 'No' END as IsAssembly, P.[DRAWING_REV_NO] as Revision, (SELECT P2.[USER_1] as ManufacturerName, P2.[ID] as PartNumber from Part P2 for xml PATH('Manufacturer')) From Part P inner join [BOM_exploded] BX on P.ID = BX.Part For XML Auto, ROOT('Parts') )AS COL_XML trying to format the xml code so that the output would be like... <?xml verion= "1.0" encoding="utf-8"?><Parts><PartNumber>01-0009*CW*FN</PartNumber><Description>IC CHOPPER STABILIZED OP AMP</Description><IsAssembly>Yes</IsAssembly><Revision>E</Revision><MANUFACTURER><ManufacturerName>CW-6</ManufacturerName><PartNumber>01-0009*CW*FN</PartNumber></MANUFACTURER></Parts>
This is the error I'm getting ...
Msg 6809, Level 16, State 1, Line 2 Unnamed tables cannot be used as XML identifiers as well as unnamed columns cannot be used for attribute names. Name unnamed columns/tables using AS in the SELECT statement.
SSIS package output differences
I have the same packages running on both SQL 2005 and SQL2016 to import data from the same Oracle database. Most of them come up with the same data. However there are big differences on some of the big tables. What is going wrong? Where should I start looking at for trouble-shooting? Thanks in advance.
How do I concatenate multiple rows into a single string to return only one row?
I have an existing query that pulls recipe information using multiple joins, but need to add allergen information. I have a query that pulls the data I need, but it returns multiple rows, one row for each allergen. I need a single row for each recipe that lists the allergens as a single string separated by commas.
This is what I have so far:
SELECT MenRecipeHeader.RecipeNumber, MenRecipeHeader.RecipeName, InvAllergies.Allergy FROM InvItemsAllergens INNER JOIN InvAllergies ON InvItemsAllergens.InvAllergyID = InvAllergies.InvAllergyID INNER JOIN InvItems ON InvItemsAllergens.InvItemsID = InvItems.InvItemID INNER JOIN MenFoodItems INNER JOIN MenRecipeHeader ON MenFoodItems.MenFoodItemID = MenRecipeHeader.MenFoodItemID ON InvItems.MenFoodItemID = MenFoodItems.MenFoodItemID WHERE (MenRecipeHeader.RecipeNumber = N'60218')
But, it returns one row per allergen....
RecipeNumber RecipeName Allergy 60218 YOGURT PARFAIT BERRY ALC Dairy 60218 YOGURT PARFAIT BERRY ALC Egg 60218 YOGURT PARFAIT BERRY ALC Treenuts 60218 YOGURT PARFAIT BERRY ALC Wheat 60218 YOGURT PARFAIT BERRY ALC Soy
I need a single row for each recipe where the allergens are all in a single string separated by commas. Like this: Dairy, Egg, Treenuts, Wheat, Soy
How can I revise the existing query to return the allergens so each recipe has only one row?
https://chaterlimited.com/sledge-hammer-xl/
sledge hammer xl And, if you’re in the bedroom with your partner, you want to knock her socks off. But, sometimes it’s hard to do just that, especially when you don’t have a lot of time to dedicate to working out. And, when you do get to the gym, you’re too tired to get the epic workout you need. You can get rid of all those hangups when you try out the incredible , the only natural supplement proven to help free up more testosterone in your body for amazing results. As guys get older, testosterone levels tank significantly. And, you can already notice major differences after age 30. But, you’re not ready to throw in the towel on your muscles yet, right? After all, no guy wants to be flabby and weak. (And, your partner doesn’t want you to be flabby either.) Well, when you take Testosterone Booster, you’ll get the testosterone and stamina you need to destroy your workout, and the nutrients your body needs to pack on.
create a pl?sql procedure that calculate total monthly income of all hotels.
write a procedure that Calculate and display total income from all sources of all hotels. Totals must be printed by month, and for each month by event and service type. Include discounts.( 10% discount if the reservation date is 2 month before reservation start date).
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_date, 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
this is what i tried, but i want to write it in a procedure form, how do i do that. please help.Thanks
select month (Reservation_end_date) as , event_type, sum(case when days>= 2 then cost- (cost/100)* 10 else cost) as total_cost) ((select distinct reservation.hotel_id,reservation_date, reservation_start_date, reservation_end_date, event_type, room.room_type as R_type ,room_cost as R_cost, months_between(reservation_start_date,reservation_date)as months from reservation, room where reservation.hotel_id = room.hotel_id;) union (select hotel_name, reservation_date, reservation_start_date, reservation_end_date, event_type, services_type, services_cost as cost, months_between(reservation_start_date,reservation_date)as month from reservation,service, hotel where reservation.services_id = service.services_id and reservation.hotel_id = hotel.hotel_id;)) group by month(reservation_end_date),event_type;
Newbie Question about Connection Strings
Hello!
Professionally I have a non-technical background and am just getting started with databases and SQL Server, so please bear with me.
I've come across this term called "connection string". What it does is connect an application to a database. In order to do that, one has to type in a connection string within the application. Is that correct?
Also, can I connect to a database from another (client) computer by running a connection string? If yes, how do I do that?
I already have a test database that I created in SQL Server Management Studio and was able to connect to it from another computer using Ethernet cable. I went through all these procedures of enabling TCP/IP and altering my Firewall's rules, so I'm just wondering if I could have done it through a connection string.
Thank you!
Generate the Dates between two Dates in sql using while loop
Below is my requirement.
I have a base table as below
create table dbo.test_problem
( MonthNumber int, MonthBeginningDate date, MonthEndDate date, YearNumber int, Quarter char(2))
insert into dbo.test_problem
select 201601,'12/23/2015','1/22/2016',2016,'Q1'
union all
select 201602,'1/23/2016','2/22/2016',2016,'Q1'
union all
select 201603,'2/23/2016','3/24/2016',2016,'Q1'
Wanted to insert dates between MonthBeginningDate and MonthEndDate into below table "PDate" column
create table test.test_solution
( MonthNumber int, MonthBeginningDate date, MonthEndDate date, YearNumber int, Quarter char(2),Pdate date)
My output should look like below
MonthNumberMonthBeginningDateMonthEndDateYearNumberQuarterPdate20160112/23/20151/22/20162016Q112/23/201520160112/23/20151/22/20162016Q112/24/201520160112/23/20151/22/20162016Q112/25/201520160112/23/20151/22/20162016Q112/26/201520160112/23/20151/22/20162016Q112/27/201520160112/23/20151/22/20162016Q112/28/201520160112/23/20151/22/20162016Q112/29/201520160112/23/20151/22/20162016Q112/30/201520160112/23/20151/22/20162016Q112/31/201520160112/23/20151/22/20162016Q11/1/201620160112/23/20151/22/20162016Q11/2/201620160112/23/20151/22/20162016Q11/3/201620160112/23/20151/22/20162016Q11/4/2016
Note: I have provided only few "Pdate" values.
For example: MonthBeginningDate -12/23/2015 and MonthEndDate - 01/22/2016
Then "PDate" should be
12/23/2015,12/24/2015,12/25/2015,,12/26/2015,,12/27/2015,12/28/2015,2/29/2015,12/30/2015,,12/31/2015,1/1/2016,1/2/2016,1/3/2016,1/4/2016,
1/5/2016,1/6/2016,1/7/2016,1/8/2016,,1/9/2016,1/10/2016,1/11/2016,1/12/2016,1/13/2016,1/14/2016,1/15/2016,1/16/2016,1/17/2016,1/18/2016,
1/19/2016,1/20/2016,1/21/2016,1/22/2016
I have implemented the above with Cursors and it is working fine in Azure SQL DB. But I need to implement this in Azure SQLDW, which is not supporting cursors.
So wanted to achieve this with While loop.
Anyone help is greatly appreciated.
Ignore parameters which are null
I am trying to run a stored proc from a web application. I have multiple parameters with OR condition but i want the parameters which are left blank by the user to be ignored when the query execute.
This is what i am trying
ALTER Proc [dbo].[spStatusReport]
@CUST_NAME varchar(20),
@CUST_CODE varchar(10) = NULL
as
SELECT CUST_CODE, DEPT_CODE,EMPLOYEE_CODE, EST_SCRAP, EXCH_RATE,
F_G_, LINE4, LOCATION
FROM Status_Report
WHERE
((@CUST_NAME IS NULL OR [LOCATION] LIKE '%' + @CUST_NAME + '%') OR
(@CUST_CODE IS NULL OR [CUST_CODE] LIKE '%' + @CUST_CODE + '%'))
But when i run EXEC spStatusReport 'ABC',''
I get everything instead of only the ABC location
How can I import a CSV file with double quotes with a comma in a field name?
Please help with import using SSIS (flat file to SQL) Issue is that site column has a double quote due to a comma in the site name in my CSV file.
Well_ID,Site,Date,METER,GL,Gas,Oil,Water,Casing,Tubing,Choke,Notes
203032.01,"GARDNER, EL AL #2H",09/23/2017,0,0,0,0,0,,,,
203032.01,"GARDNER, EL AL #2H",09/24/2017,0,0,0,0,0,,,,
203032.01,"GARDNER, EL AL #2H",09/25/2017,0,0,0,0,0,,,,
203078.01,HAWN DICKSON #1H,09/23/2017,0,0,0,0,0,,,,
203078.01,HAWN DICKSON #1H,09/28/2017,0,0,0,0,0,,,,
203409.01,PORCUPINE #1H,09/28/2017,0,0,0,0,0,,,,
203411.01,BADGER #1H,09/23/2017,0,0,0,0,0,,,,
So my site name is for "GARDNER, EL AL #2H" is split between column site and Date thus my data is importing incorrectly to SQL table
Can someone please help me this SSIS question ? Thanks in advance.
SQL AGENT SSIS JOBS IN HUNG STATE
SQL SERVER VERSION:Microsoft SQL Server 2014 (SP2-CU10-GDR) (KB4052725) - 12.0.5571.0 (X64)
Copyright (c) Microsoft Corporation
Enterprise Edition: Core-based Licensing (64-bit) on Windows NT 6.3 <X64> (Build 9600: )
OS version - WINDOWS SERVER 2012 R2 STANDARD
SSIS - SQL 2014 - Microsoft SQL Server 2014 (SP2-CU10-GDR) (KB4052725)
Last few months we are facing the issues 2 -3 times
We have observed that Jobs which are scheduled using T-SQL are getting completed successfully, issue is with SQL jobs which are configured by SSIS and those are getting halted after some time post re-starting the Integration service.
The SSIS Jobs will works for while and start to get hung and wont do anything -Anyone can tell me what could be the issue Why only the SSIS jobs hung and others are works fine?
Scheduling a Report
Hey Guys Sorry if this is not where I should be posing this question.
I have few reports that I am scheduling and I don't want to use (Credentials stored securely in the report server - Use as Windows credentials when connecting to data source) - I want to use Windows Integrated security and I am getting the error (Subscriptions cannot be created because the credentials used to run the report are not stored, or if a linked report, the link is no longer valid).
Is there a way around this for scheduling a report pointing to a Data Source.?
Thanks much.
Could any one tell me what is the script to compare two database schema and prepare the list of differences
abc@gmail.com
Sql server 2017 performance
I have a query which works well in sql server 2014 filetables , after sql server 2017 upgrade it performs worse.
Query Prototype:
select cached_file_size from filetable where streamid='88656899'
Union
Select cached_file_size from filetablehistory where streamid='88656899'
Below Observations working fine:
1.
select cached_file_size from filetable where streamid='88656899'
Union all
Select cached_file_size from filetablehistory where streamid='88656899'
2.
select cached_file_size from filetable where streamid='88656899'
3.
Select cached_file_size from filetablehistory where streamid='88656899'
4. There are no locks held on those tables.
Please help!!
Report using Network Logged in User
Guys,
I have a report using a parameter picking up the logged in user on the network and doing trimming on it to remove the Domain part of it (Domain\UserID). The report sends missing timesheet for every user in the Division on a certain date. When you click on the report on the Report Server it works great and picks up the logged in user and their missing timesheets if there are any.
Here is the issue when I schedule the report through subscription and gets sent everyone gets my report and not their respective user ID on the network.
I have searched everywhere for options on how to do it and came up empty handed. People mentioned using Data Driven Subscription and I tried that but there is nowhere on there where you can set any parameters.
Any Help Would be greatly appreciated.
Step By Step Instructions To Get It Ultra Garcinia 360 Slim
The other advantage of the enhancement is to some degree identified with the primary advantage talked about, however it tends to an issue past beautifying agents, that is, Ultra Garcinia 360 Slim. Leptin is a hormone that tells the cerebrum that it has enough sugar to perform different capacities, keeping individuals from gorging. In any case, there are individuals who are leptin safe, which implies that their mind does not get this flag. Therefore, they will in general gorge, which at that point prompts corpulence. Overweight and hefty individuals really will in general have large amounts of leptin, yet they are simply not delicate to it. By taking the enhancement, be that as it may, their leptin affectability increments. Their nourishment longings are then smothered, helping them get more fit steadily. Click here to more information https://ketoneforweightloss.com/ultra-garcinia-360-slim/