Posts

Showing posts with the label sql-server

ASP.Net Meta Tags: Programmatically populate Title, Keywords and Description in Page Head Section from database

Image
ASP.Net Meta Tags: Programmatically populate Title, Keywords and Description in Page Head Section from database I'm trying to create search option in my ASP.net application to check Doctor details based on Location. If I try the below code, only home page is showing. http://example.com/Metatag/Home.aspx . I want the URL to be changed as per location. Example expected URL: http://example.com/Metatag/chennai/doctors/saidapet http://example.com/Metatag/Home.aspx http://example.com/Metatag/chennai/doctors/saidapet I'm new to this technology. Page Load protected void Page_Load(object sender, EventArgs e) { string page = Request.Url.Segments[Request.Url.Segments.Length - 1]; string location = Request.Url.Segments[Request.Url.Segments.Length - 1]; DataTable dtMeta = this.GetData(page,location); //Add Page Title this.Page.Title = dtMeta.Rows[0]["Title"].ToString(); //Add Keywords Meta Tag HtmlMeta keywords = new HtmlMeta(); keywords.Ht...

Sql Triggers-Implementation Issue

Sql Triggers-Implementation Issue Hi guys i am making 2 tables for implementing triggers-- create table emp(id int primary key identity(1,1), name char(40), salary varchar(50), gender char(40), departmentid int); insert into emp(name,salary,gender,departmentid) values ('jimmi',4800,'Male',4); create table emp_audit ( id int primary key identity(1,1), audit varchar(60) ); alter trigger trigger_em_update on emp for update as begin Declare @Id int Declare @oldname char(40),@newname char(40) Declare @oldsal int,@newsal int Declare @oldgen char(40),@newgen char(40) Declare @olddeptid int,@newdeptid int Declare @auditstring nvarchar(max) --select * from deleted; select * into #temptable from inserted; while(Exists(select id from #temptable)) --boolean condition if there are rows are not Begin set @auditstring ='' --if there are many rows we still select the first one select Top 1 @Id =id,@newname=name,@newgen=gender,@newsal=salary,@newdeptid=departmentid ...

Azure SQL DB causing connection time out for stored procedures

Azure SQL DB causing connection time out for stored procedures We have hosted our database in Azure and are running stored procedures on this DB. The stored procedures had been running fine till last week but suddenly started giving error connection timeout. Our database size is 14 GB and the stored procedures in general return 2k to 20k records and we are using the S3 pricing tier (50 DTU) of Azure DB. What I found interesting was the first time the stored procedure is executed, it takes a lot of time 2 - 3 mins and this is causing the timeout. The later executions are fast (maybe it caches the execution plan). Also when I run on the same DB with the same number of records on a machine with the config of 8gb ram, Win10 it runs in 15 seconds . This is my stored procedure: CREATE PROCEDURE [dbo].[PRSP] @CompanyID INT, @fromDate DATETIME, @toDate DATETIME, @ListMailboxId as MailboxIds Readonly, @ListConversationType as ConversationTypes Readonly AS BEGIN ...

Assistance with SQL Query to break down bill of materials

Assistance with SQL Query to break down bill of materials I am try to breakdown a BOM into its lowest items. I have got 2 tables. Table A: ITEM FORMULA -------------------- 7024 BDD39 7024 BDD94 Table B FORMULA RAW_ITEMS --------------------------------------- BDD94 BioxDD 94 RMW0005 BDD94 BioxDD 94 RMP0007 BDD94 BioxDD 94 RMD0010 BDD94 BioxDD 94 RMH0009 BDD39 BioxDD 39 RMA0005 BDD39 BioxDD 39 RMW0006 BDD39 BioxDD 39 RMS0005 Is there any hint as to how to go about to replace the item in Table A with all the 3 items in Table B? My expected output is: Item ----------------------------------------- 7024 BDD39 BioxDD 39 RMA0005 7024 BDD39 BioxDD 39 RMW00...

How to import an .xlsx file into a SQL Server database on MacOS?

How to import an .xlsx file into a SQL Server database on MacOS? I've set up an SQL server using Docker on MacOS computer. I've also installed SQL Operations Studio as a GUI. In SQL Operations Studio I'm trying to import list "Data" from a multiple-sheet AllData.xlsx file into a newly created table "Data_test" in my database "TestDB" using this chunk of code: USE TestDB; GO SELECT * INTO Data_test FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0', 'Excel 12.0; Database=/Users/user_name/Desktop/AllData.xlsx', [Data$]); GO I am getting an error like this: "The OLE DB provider "Microsoft.ACE.ODBC.12.0" has not been registered." Is there any way to solve this issue? A question like this has already been attempted to answer by this link. It is advised to use ODBC instead of OLEDB, but the link given in the answer refers to importing into Excel from a database, which is the opposite of what I'm trying to do. Overa...

I need postgresql version of this function

I need postgresql version of this function I am newbie to postgresql and I need a postgresql version of this function - could you help me please? CREATE FUNCTION [dbo].[getpersonname] (@commid INT) RETURNS VARCHAR(255) AS BEGIN DECLARE @personnname varchar(255) SELECT @personnname = COALESCE(@personname + ',', '') + ISNULL(CONVERT(VARCHAR(50), pers.personnname ),'') FROM dbo.comlink comli INNER JOIN dbo.person pers ON personid= comli_personid WHERE comli.comli_commid = @commid RETURN @personnname END What does the function do? – a_horse_with_no_name Jul 1 at 5:11 1 Answer 1 If I understand that code correctly it returns all names separated with c...

MDX Scope Total Calculation with condition

MDX Scope Total Calculation with condition I recently encounter an issue with using scope to calculate grand total. Example I've create a measure : CREATE MEMBER CURRENTCUBE.[Measures].[test Invoice 2 Amt] AS IIF(ISEMPTY([Measures].[Amount]), NULL, [Measures].[SalesInvoiceLine2_Amt]), FORMAT_STRING = "#,#.00", VISIBLE = 1; This measure to ensure amount2 (SalesInvoiceLine2_Amt) only appear when another measure (Amount) have value. But now the issue is my grand total for Amount2 doesn't total based on above condition, instead it sum up all amount2. I've try to use scope but seems doesnt work as well. CREATE MEMBER CURRENTCUBE.[Measures].[test Invoice 2 Amt] AS IIF(ISEMPTY([Measures].[Amount]), NULL, [Measures].[SalesInvoiceLine2_Amt]), FORMAT_STRING = "#,#.00", VISIBLE = 1; SCOPE ( [Measures].[test Invoice 2 Amt] ); THIS = SUM(IIF(ISEMPTY([Measures].[Amount]), NULL, [Measures].[SalesInvoiceLine2_Amt])) ; End Scope; [Item] [Amount] [test Invoice 2 Amt] [...

If I have tblBookInfo (bookId, title… etc.) and I want it to have categories column, what is the best way to do it?

If I have tblBookInfo (bookId, title… etc.) and I want it to have categories column, what is the best way to do it? If I have tblBookInfo (bookId, title... etc.) and I want it to have categories column, what is the best way to do it? categories table will have FK related to bookId like this bookId title 1 test title 2 test title 2 bookId name 1 Science fiction 1 Mystery 1 Horror 2 Science fiction 2 Mystery In this case, category name will be repeated many times and it's ugly Store an array of int in btlBookInfo like this bookId title categories 1 test title [1,2,3] 2 test title 2 [1,2] I heard storing array in a column is not a best practice as asked here Leave the categories table as it is like this id name 1 Science finction 2 Mystery 3 Horror And add a FK to tblBookInfo like this bookId title categoryId 1 test title 1 2 ...

How to select only first ROW_NUMBER combined with SUM

Image
How to select only first ROW_NUMBER combined with SUM I like to group my table by [ID] while using SUM and also bring back [Product_Name] of the top ROW_NUMBER - not sure if I should use ROW_NUMBER , GROUPING SETS or loop through everything with FETCH... this is what I tried: ROW_NUMBER ROW_NUMBER GROUPING SETS DECLARE @SampleTable TABLE ( [ID] INT, [Price] MONEY, [Product_Name] VARCHAR(50) ) INSERT INTO @SampleTable VALUES (1, 100, 'Product_1'), (1, 200, 'Product_2'), (1, 300, 'Product_3'), (2, 500, 'Product_4'), (2, 200, 'Product_5'), (2, 300, 'Product_6'); SELECT [ID], [Product_Name], [Price], SUM([Price]) OVER (PARTITION BY [ID]) AS [Price_Total], ROW_NUMBER() OVER (PARTITION BY [ID] ORDER BY [ID]) AS [Row_Number] FROM @SampleTable T1 My desired results - only two records: 1 ...

Archiving data from Table1 to Table2 upon condition | Sql Server 2017 Express

Archiving data from Table1 to Table2 upon condition | Sql Server 2017 Express I have a database with two tables: Table Student with the following columns: Student StudentID int identity, StudentFN, StudentLN, Active bit, EnrollmentDate Table ArchivedStudent with the following columns: ArchivedStudent ArvchivedStudentID int identity, StudentID int, StudentFN, StudentLN, WithdrawalDate getdate(), ReasonDropped In the long run, I'd like to schedule automatic updates for the table AcrchivedStudent and move the data from columns StudentID, StudentFN and StudentLN from table Student to table ArchnivedStudent when column Active changes from 1 (true) to 0 (false). AcrchivedStudent StudentID, StudentFN StudentLN ArchnivedStudent Here's my start up script that is not working: update [as] set [as].StudentID = s.StudentID, [as].StudentFN = s.StudentFN, [as].StudentLN = s.StudentLN from ArchivedStudent [as] inner join Student s on [as].StudentID = s.StudentID where s.Active = 0 go ...

SQL how to exclude bank Holiday and Christmas DAY on Date diff

SQL how to exclude bank Holiday and Christmas DAY on Date diff Any advice will be highly appreciated How to exclude Bank holidays, Christmas DAY in date datediff in the UK I have a customer table with all the customer booking in a hotel, I would like to calculate the length of stay but I want to exclude bank holidays and other holidays in the UK. Many thanks SELECT [StartDate], DATEDIFF(DAY,[StartDate],[EndDate]) AS Bookingdays ,[EndDate] ,[CustomerId] ,[BookingID] FROM [CustomerBooking] Search for Calendar Table. – Dan Guzman Jun 30 at 10:51 Elaborating Dan Guzman's comment: (1) create Calendar Table. (2) mark the unique days in the Calendar Table. (3) select the dates from the Calendar Table which are between the [StartDate] and [EndDate] and that the column for unique days is not i...

Transaction (Process ID) was deadlocked errors

Transaction (Process ID) was deadlocked errors I am having an issue with my code and the numerous SQL calls that it makes with deadlocks. I pasted the code into PasteBin here: https://pastebin.com/p1YDkKsB. Can someone help me out here? It happens most often in the CheckClanActivity task here: using(SqlCommand cmd = new SqlCommand(string.Format("select * from ClanMembers where MembershipId={0} and IsActive = 1", entry.Player.DestinyUserInfo.MembershipId), conn)) , but it also happens all over the place. Edit: Okay, the involved SQL statements are as follows: if not exists(select * from ClanMembers where MembershipId={0}) begin insert into ClanMembers(ID, MembershipId, BattleNetId, ClanId, DateLastPlayed, IsActive, LastUpdated) select ISNULL(MAX(ID) + 1, 0),{0},'{1}',{2},'{3}', 1, GETDATE() from ClanMembers end else begin update ClanMembers set DateLastPlayed='{3}', LastUpdated=GETDATE() where MembershipId={0} end if not exists(select * from ClanMemberC...

How to change bytes of array into image?

Image
How to change bytes of array into image? I have a csv file, which was extracted from MS SQL database with image column included. My task is to convert the contents of each row in image column into image and save it as image file. Here is the content of a row- https://drive.google.com/open?id=1J_jz5vN8ATxJ5Qw_c8l0qqKFrIee8kHF As the contents length exceeds the limited word count, I uploaded it to google drive. I changed it to bytearray and try to write it to new file and read it as an image but I haven't got the image. https://drive.google.com/open?id=1h-7cRiTWErZzmMJYmc6XmLmeLK982WZR How could I convert that bytearray to the image?? I have tried writing it to new file and reading it with io. I have spent 8+ hours on this and have tried every solutions found on stackoverflow. Please help me find the solution. Here is my code - df = (pd.Series(df['image'])) df = df.dropna() x = df[3] print (x) bytes = base64.b64decode(x) print (bytes) image = open("new.jpeg",...

Returning multiple records using first/earliest date

Returning multiple records using first/earliest date This is a simple concept but the LINQ/SQL solution has me stumped! In the example data below, for each ID I need to retrieve one ISRC , taking the earliest dated one for each. ISRC The data is sorted by ID/ReleaseDate/ISRC , so I could read the first/top record for each ID. ie ID 1 = GBMNA1600001 , ID 2 = GBMNA1600002 , ID 3 = GBMNA1600003 , ID 20 = GBMNA1680058 ... ID/ReleaseDate/ISRC ID ProductID ISRC ReleaseDate 1 16 GBMNA1600001 2016-03-27 00:00:00.0000000 1 26 GBMNA1680038 2016-04-24 00:00:00.0000000 1 32 GBMNA1680057 2016-05-01 00:00:00.0000000 1 132 GBMNA1680482 2016-11-13 00:00:00.0000000 1 223 GBMNA1781107 2017-03-26 00:00:00.0000000 2 5 GBMNA1600002 2016-02-14 00:00:00.0000000 2 32 GBMNA1680049 2016-05-01 00:00:00.0000000 3 13 GBMNA1600003 2016-03-13 00:00:00.0000000 3 38 GBMNA1680095 2016-05-29 00:00:00.0000000 3 485 GBMNA1880099 2018-06-26 00:00:00.0000000 20...

Spring boot jpa and ms sql update issues

Spring boot jpa and ms sql update issues I’m working on a REST web service and I want to migrate from “postgres” database and PHP (the existing web service), to microsoft sql server 2012 and spring boot. So, I have generated entities using Netbeans IDE from the existing “postgres” database. Here’s an example of a generated entity: @Entity @Table(schema = "dbo") @XmlRootElement @NamedQueries({ @NamedQuery(name = "Activite.findAll", query = "SELECT a FROM Activite a"), @NamedQuery(name = "Activite.findById", query = "SELECT a FROM Activite a WHERE a.id = :id"), @NamedQuery(name = "Activite.findByLabel", query = "SELECT a FROM Activite a WHERE a.label = :label"), @NamedQuery(name = "Activite.findByType", query = "SELECT a FROM Activite a WHERE a.type = :type"), @NamedQuery(name = "Activite.findByDateOperation", query = "SELECT a...