|
This sort of business rule should be in your application not the database. Wrong tool for the job.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi All,
I have a Constraint as below, I need to keep the same Index but remove this Unique Constraint, can anybody please help me? Any help like a link, suggestion or code snippet, anything helps.
Thanks in advance.
ADD CONSTRAINT TableName_UniqueConst UNIQUE (ShortName, Name, SecondaryName, Address1, Address2, Address3);
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
Hello,
I Am beginer in asp.net and Sql server , i want to do a query to calculate student grade point and grade using the condition bellow.
WHEN EXAMS BETWEEN 75 AND 100 THEN 'A'
WHEN EXAMS BETWEEN 70 AND 74 THEN 'AB'
WHEN EXAMS BETWEEN 65 AND 69 THEN 'B'
WHEN EXAMS BETWEEN 60 AND 64 THEN 'BC'
WHEN EXAMS BETWEEN 55 AND 59 THEN 'C'
WHEN EXAMS BETWEEN 50 AND 54 THEN 'CD'
WHEN EXAMS BETWEEN 45 AND 49 THEN 'D'
WHEN EXAMS BETWEEN 40 AND 44 THEN 'E'
WHEN EXAMS BETWEEN 40 AND 0 THEN 'F'
please helo me with this issue than you .
|
|
|
|
|
Aliyu Usman wrote: please helo me with this issue Sure what have you tried so far.
Hint
Select from the results table and group by the result values or use a CASE statement and then group by the grade.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
hello,
bellow is the query i have tried
SELECT
ADMISSION_NO,
FULL_NAME,
EXAMS,
CASE
WHEN EXAMS BETWEEN 75 AND 100 THEN 'A'
WHEN EXAMS BETWEEN 70 AND 74 THEN 'AB'
WHEN EXAMS BETWEEN 65 AND 69 THEN 'B'
WHEN EXAMS BETWEEN 60 AND 64 THEN 'BC'
WHEN EXAMS BETWEEN 55 AND 59 THEN 'C'
WHEN EXAMS BETWEEN 50 AND 54 THEN 'CD'
WHEN EXAMS BETWEEN 45 AND 49 THEN 'D'
WHEN EXAMS BETWEEN 40 AND 44 THEN 'E'
WHEN EXAMS BETWEEN 40 AND 0 THEN 'F'
END AS GP
FROM R_Upload_2
|
|
|
|
|
And what is the problem?
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Aliyu Usman wrote: WHEN EXAMS BETWEEN 40 AND 0 THEN 'F' You need to reverse this so that you have:
BETWEEN 0 AND 40
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
modified 24-Nov-15 8:23am.
|
|
|
|
|
I have created a CLR which uses the newtonsoft json parser.
I need to deploy the CLR. I have created an assembly for the parser dependency:
CREATE ASSEMBLY [Newtonsoft.Json] FROM 'C:\share\Release\Newtonsoft.Json.dll' WITH PERMISSION_SET = UNSAFE
The above statement throws an error:
Assembly 'Newtonsoft.Json' references assembly 'system.runtime.serialization, version=3.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089.', which is not present in the current database. SQL Server attempted to locate and automatically load the referenced assembly from the same location where referring assembly came from, but that operation has failed (reason: 2(failed to retrieve text for this error. Reason: 15105)). Please load the referenced assembly into the current database and retry your request.
I am using version 7.xx of the parser.
I am targeting .NET 3.5
What is the proper procedure for deploying the CLR to sql server 2008 r2?
|
|
|
|
|
hi
i have this table:
id | Name | Age
==================
1 | AAA | 22
1 | AAA | 22
2 | BBB | 33
2 | BBB | 33
2 | BBB | 33
3 | CCC | 44
4 | DDD | 55
i need to delete from this table all the duplicate records
and leave only one record.
the table will looks like this:
id | Name | Age
==================
1 | AAA | 22
2 | BBB | 33
3 | CCC | 44
4 | DDD | 55
i work with sqlCE for Mobile
thanks
|
|
|
|
|
This is very much a solved problem, the minimum of research [^] would get you plenty of examples
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Try this
CREATE TABLE tblTest (ID INT, NAME VARCHAR(20),AGE INT)
INSERT INTO tblTest VALUES(1,'AAA',22),(1,'AAA',22),(2,'BBB',33),(2,'BBB',33),(2,'BBB',33),(3,'CCC',44),(4,'DDD',55)
CREATE TABLE tblTestDuplicate (ID INT, NAME VARCHAR(20),AGE INT)
INSERT INTO tblTestDuplicate
SELECT *
FROM tblTest
GROUP BY ID,NAME,AGE
HAVING COUNT(ID) > 1
DELETE FROM
tblTest
WHERE ID IN (SELECT ID FROM tblTestDuplicate)
INSERT INTO tblTest
SELECT *
FROM tblTestDuplicate
SELECT *
FROM tblTest
ORDER BY ID
DROP TABLE tblTestDuplicate
DROP TABLE tblTest
/*
ID NAME AGE
1 AAA 22
2 BBB 33
3 CCC 44
4 DDD 55
*/
Hope this helps
modified 15-Nov-15 23:11pm.
|
|
|
|
|
Hello SQL Gurus,
I am seriously struggling with this.
I would like the following records to display column names along with total records belonging to each division(e.division).
However, I can't even get the records to display the correct results.
It displays all the records correctly but does not indicate how many records belong to each division.
What am I doing wrong?
SELECT e.empnum, a.filenameName, a.filePath, e.empname, e.department, e.UnitName,x.total
FROM
Employee e INNER JOIN Applyers a ON a.EmpNum = e.empnum
JOIN (SELECT total = COUNT(*) FROM Employee e INNER JOIN Applyers a ON a.EmpNum = e.empnum) AS x ON a.EmpNum = e.empnum
where e.Department='IT'
Any ideas what I am doing wrong?
|
|
|
|
|
Your total is not going to make any sense as you are returning every Employee/Applyer record and putting the total on each record.
You need to craft your query better, get your granular data, including the departmentno into a query first. Then decide what you want to see from the results. What you probably don'y want is multiple employee records with the department total on each line.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
@samflexx, I have simulated your situation and have made a solution that I think matches your requirement.
Since you said that
total records belonging to each division
the obvious idea that cropped up is to use the ROLLUP function. I am presenting the solution. Let us know if it has helped you
;WITH CTE AS(
SELECT
1 AS EMPNUM
,'File1'AS FILENAME
,'Name1' AS EMPNAME
,'Division1' AS Division UNION ALL
SELECT
2 AS EMPNUM
,'File2'AS FILENAME
,'Name2' AS EMPNAME
,'Division2' AS Division UNION ALL
SELECT
3 AS EMPNUM
,'File12'AS FILENAME
,'Name12' AS EMPNAME
,'Division1' AS Division UNION ALL
SELECT
4 AS EMPNUM
,'File14'AS FILENAME
,'Name14' AS EMPNAME
,'Division1' AS Division UNION ALL
SELECT
5 AS EMPNUM
,'File21'AS FILENAME
,'Name21' AS EMPNAME
,'Division2' AS Division UNION ALL
SELECT
6 AS EMPNUM
,'File3'AS FILENAME
,'Name3' AS EMPNAME
,'Division3' AS Division) -- table create and data insertion part
-- Query starts
SELECT
X.*
FROM(
SELECT
EMPNUM = ISNULL(CAST(t.EMPNUM AS VARCHAR(10)), ' ')
,FILENAME = ISNULL(CAST(t.FILENAME AS VARCHAR(10)), ' ')
,EMPNAME = ISNULL(CAST(t.EMPNAME AS VARCHAR(10)), ' ')
,Division = CASE
WHEN t.Division IS NULL AND t.EMPNUM IS NULL THEN 'Total :-'
WHEN t.EMPNUM IS NULL THEN 'Total ' + t.Division + ' Count :-'
ELSE t.Division END
,DivisionCount = COUNT(t.Division)
FROM CTE t
GROUP BY ROLLUP(t.Division,t.EMPNUM,t.EMPNAME,t.FILENAME))X
WHERE (LEN(X.FILENAME) > 0 AND LEN(X.EMPNAME) > 0)
OR (LEN(X.FILENAME) = 0 AND LEN(X.EMPNAME) = 0 AND LEN(X.EMPNUM) = 0)
The output
EMPNUM FILENAME EMPNAME Division DivisionCount
1 File1 Name1 Division1 1
3 File12 Name12 Division1 1
4 File14 Name14 Division1 1
Total Division1 Count :- 3
2 File2 Name2 Division2 1
5 File21 Name21 Division2 1
Total Division2 Count :- 2
6 File3 Name3 Division3 1
Total Division3 Count :- 1
Total :- 6
modified 13-Nov-15 23:14pm.
|
|
|
|
|
So I have this SQL Linq statement, pretty easy until I added Free Shipping.
In the original statement, I get the data from ORDER_COMPLETED and do a join to SHIPPING_REALTIME in which I grab the Realtime rate name.
But Now, I added Free Shipping, by using another table that holds my criteria. So now I have 2 tables to get the rate name from, the other called SHIPPING_FREEMATRIX
I'm trying to think of a better more proper way to do this.
So what I have so far is
pResults = _
(
From oc In context.Order_Completed
Join srt In context.Shipping_Realtime On srt.RateAPICode Equals oc.RateAPICode
Where oc.OrderStatus = "QUEUED_FOR_FULFILLMENT" _
Or oc.OrderStatus = "OUT_FOR_FULFILLMENT" _
Or oc.OrderStatus = "ORDER_CANCELED" _
And oc.OrderDate >= DbFunctions.AddDays(Today, -7)
Order By oc.OrderNumber
Select New coOrderIndex With
{
.OrderID = oc.CompletedOrderID,
.OrderDate = oc.OrderDate,
.OrderNumber = oc.OrderNumber,
.OrderStatus = oc.OrderStatus,
.LoginID = oc.LoginID,
.GrandTotal = oc.GrandTotal,
.RateAPICode = oc.RateAPICode,
.RateCharge = oc.TotalNetCharge,
.RateAPIName = If(srt.RateName Is Nothing, "", srt.RateName)
}
).AsEnumerable()
pValue = pResults.Count()
I tried using a tenary operator on RateName, but got an error saying First or Single can only be used at the end of the statement.
.RateAPIName = If(
I tried a function but got the error can't execute an external function within a store statement
.RateAPIName = get_rateAPIName(oc.RateAPICode)
I tried a double join but got nothing
Join srt In context.Shipping_Realtime On srt.RateAPICode Equals oc.RateAPICode
Join fsm In context.Shipping_FreeMatrix On fsm.RateAPICode Equals oc.RateAPICode
I thought about taking the pResults and just looping back through using for each and populating the RateAPI Name, but I tried the above methods instead and aborted this thought.
for each pResult as coOrderIndex in pResults
pResult.RateAPIName =
next
If it was a single record that was easy for me, but doing it with multiple records is, well I'm not sure how to proceed.
|
|
|
|
|
I assume the SHIPPING_FREEMATRIX is not having corresponding rows for all rows in ORDER_COMPLETED.
If that's the case you'll need to do an outer join.
Here's[^] how to do that in query syntax.
|
|
|
|
|
That was hard to do. I got confused on whether to do a Join and Outer Join, so I had to experiment with it. But I got it to work in LinqPad4
Dim orders = _
(
From oc In context.Order_Completed
Group Join srs In context.Shipping_Realtime On oc.RateAPICode Equals srs.RateAPICode Into rRates = Group From srs In rRates.DefaultIfEmpty()
Group Join fsm In Context.Shipping_Free_Matrix On oc.RateAPICode Equals fsm.RateAPICode Into fRates = Group From fsm In fRates.DefaultIfEmpty()
Where oc.OrderStatus = "QUEUED_FOR_FULFILLMENT" _
Or oc.OrderStatus = "OUT_FOR_FULFILLMENT" _
Or oc.OrderStatus = "ORDER_CANCELED" _
And oc.OrderDate >= DbFunctions.AddDays(Today, -7)
Order By oc.OrderNumber
Select New With
{
.OrderID = oc.CompletedOrderID,
.OrderDate = oc.OrderDate,
.OrderNumber = oc.OrderNumber,
.OrderStatus = oc.OrderStatus,
.LoginID = oc.LoginID,
.GrandTotal = oc.GrandTotal,
.RateAPICode = oc.RateAPICode,
.RateCharge = oc.TotalNetCharge,
.RateAPIName = If(Not srs.RateName is Nothing, srs.RateName, fsm.RateName)
}
).AsEnumerable()
Thanks for the point in the right direction!
I didn't know what to search for.
|
|
|
|
|
Personally I prefer Method syntax[^] to Query syntax as the similarity to SQL confuses me rather than helps me.
|
|
|
|
|
I've been writing more method syntax in my new MVC projects in c#.
I guess I was trying to just get this to work, and didn't want to totally rewrite it.
This isn't a new project, just an expansion of my web forms based eCommerce program that I converted to Entity Framework over the summer, and flattened out the tables like you suggested last year, a total database overhaul. But for whats it worth, your advice has finally paid off for me, I haven't a complaint in over 30 days now. I'm stilling getting the hang of SQL Linq, and my Data Access Layer.
All I have left now is to convert my web forms based app to a responsive design using the twitter bootstrap, and go back to the DAL for automatic database creation.
If I haven't thanked you yet for the help and advice you gave me, then thank you very much. And yes I did implement it all.
|
|
|
|
|
|
Hi all,
There is a bad game going on here that there was a column in the table that's dropped. Can anybody please help me in finding who has dropped that column. Anything like that like table, column or a view I want to check who dropped it.
I am also googling, if anybody can help it would be a great help, any link, suggestion or code snippet would be greatly helpful.
Thanks in advance buddy.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
Profiler might help.
If you are not tracking it this is a problem.
In the future you might look at setting up SQL Sever Profiler or using a third party (we use Idera Compliance Manager).
Mongo: Mongo only pawn... in game of life.
|
|
|
|
|
Try
SELECT SUSER_SNAME([Transaction SID])
FROM fn_dblog (NULL, NULL)
WHERE [Transaction Name] = 'DROPOBJ'
e.g.
USE [TestDB]
GO
CREATE TABLE [dbo].[tblTestEmployee]
(
[EmployeeID] [int] IDENTITY(1,1) NOT NULL,
[EmpName] [varchar](100) NOT NULL,
[Address] [varchar](100) NOT NULL
)
INSERT INTO [dbo].[tblTestEmployee]
VALUES('Emp1','Address1'),('Emp2','Address2'),('Emp3','Address3'),('Emp4','Address4')
ALTER TABLE [dbo].[tblTestEmployee] DROP COLUMN [Address]
GO
SELECT SUSER_SNAME([Transaction SID])
FROM fn_dblog (NULL, NULL)
WHERE [Transaction Name] = 'DROPOBJ'
GO
Result
sa
You can also have a look at Audit SQL Server database and see who deleted a column value
Hope this helps
|
|
|
|
|
Have you used the Apex auditor app and if so was there a noticeable performance hit.
Useful bits of info thanks...
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
No, these can only be found if you are logging anything in your system. Like, which account initiated which request, which request made what change and what time it was etc. These type of logged data can help in understanding what went wrong (if the actions were wrong) and who made a change.
If there is no log, then stop searching any further because there ain't any. But this one loss would teach you to create a logging system in your environment. The system would log the changes being made, it would store the user's ID, time of change and what change was made.
In my opinion, you should also keep a backup of your databases so that if (under any case) a table is lost or data is not integrated anymore, you can revert it back to a previous version.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|