|
SELECT everything from your resultset in reverse order.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
select T.ElectionDtlID, T.PartyShortNameEng, T.ConstituencyName, T.VotesObtained
FROM (select * from tblElectionsDetail where ConstituencyName='NA 108' and electionyear='2013' order by VotesObtained desc limit 2) T order by T.VotesObtained asc;
--
Arman
|
|
|
|
|
hi experts,
can anyone guide me ,how to decrypt the encrypted user defined function in sql server 2008
|
|
|
|
|
Your question makes no sense: are you saying that the functions, itself, is encrypted and you need to decrypt it or the output from the function? In either case, speak to the original author of the function: there is no earthly way that anyone here could possibly guess at the encryption used.
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair.
Those who seek perfection will only find imperfection
nils illegitimus carborundum
me, me, me
me, in pictures
|
|
|
|
|
|
hi,
thanks for replying...by d way i am not hacking anyone's db...i tried my function...i succeeded in encrypting but couldn't succeed in decrypting it....ie i asked in this forum...once again thanks for replying...
|
|
|
|
|
Member 8701813 wrote: by d way i am not hacking anyone's db I do not see any other reason to decrypt a procedure.
Member 8701813 wrote: i succeeded in encrypting but couldn't succeed in decrypting it There are some tools and some sprocs that can decrypt an sproc/function on Sql2005. None of those will work on Sql2010, and that change "might" have been introduced in Sql2k8R2. In that case, you're out of luck.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Encryption / Decryption
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[fn_Cryptography]
(
@String varchar(50)
)
/*
Author: POONGUNRAN S
Create date: 29-May-2013
Description: Encrypt / Decrypt
Parameters : @String - String to be encrypted / decrypted
*/
RETURNS varchar(50)
AS
BEGIN
IF @String = ''
RETURN ''
SELECT @String = LTRIM(RTRIM(@String))
DECLARE @Key varchar(50), @Crypt varchar(50), @Len smallint, @n smallint
SELECT @n = 235
SELECT @Key = ''
WHILE @n <= 255
BEGIN
SELECT @Key = @Key + CHAR(@n)
SELECT @n = @n + 1
END
SELECT @Crypt = ''
SELECT @Len = LEN(@String)
SELECT @n = 1
WHILE @n <= @Len
BEGIN
SELECT @Crypt = @Crypt + CHAR(ASCII(SUBSTRING(@String,@n,1)) ^ ASCII(SUBSTRING(@Key,@n,1)))
SELECT @n = @n + 1
END
RETURN @Crypt
END
Input put:
Select dbo.fn_Cryptography('test')
o/p : Ÿ‰žš
select dbo.fn_Cryptography('Ÿ‰žš')
o/p : test
|
|
|
|
|
Hello everyone,
I created a table which has following columns Sl_no,name and employee_id.
Is that a possible when i select a table i should get a designation of an employee in place of his name??
Kindly please help me out.
|
|
|
|
|
What we are supposed to be telepathic!
What database server
What is your select query
There is no field called designation in your table!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
We are some kind of "gods" and we can read minds
|
|
|
|
|
Shiv irfi wrote: I created a table which has following columns Sl_no,name and employee_id
SELECT Sl_no, name, employee_id
FROM [a table]
WHERE 1=1
Shiv irfi wrote: Is that a possible when i select a table i should get a designation of an employee in place of his name?? Yes.
SELECT Sl_no, designation, employee_id
FROM [a table]
WHERE 1=1
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
hi,
If you had a separate table for the designations for that employees then u can join both the tables and get what ever fields u have and make aliasing names for that columns... Otherwise it is not possible to get because u are not having the designation column in the Your table
|
|
|
|
|
Hi
First create Employee table
CREATE TABLE EMPLOYEE
(
Sl_no int identity,
Name varchar(40),
Employee_id int
)
insert the values
INSERT INTO EMPLOYEE(Name,Employee_id)
SELECT 'Anil',1001
UNION ALL
SELECT 'Mahesh',1002
UNION ALL
SELECT 'Raju',1003
then create designation table
CREATE TABLE DESIGNATION
(
Employee_id INT,
Designation varchar(30)
)
then insert the values
INSERT INTO DESIGNATION
SELECT 1001, 'Developer'
UNION ALL
SELECT 1002, 'Tester'
UNION ALL
SELECT 1003, 'Trainee'
then follow this query
SELECT E.*,D.Designation FROM EMPLOYEE E INNER JOIN DESIGNATION D ON E.Employee_id=D.Employee_id
Prakash.ch
|
|
|
|
|
Here's a problem I've come up against on a number of occasions and I have so far failed to come up with an elegant query to deal with it. I feel the GROUP BY clause might have to come into play but I don't really know how.
Let's say I have a table called Orders containing information on orders received from customers. The table has the following columns:
CustomerID (INT)<br />
OrderPlaced (DATETIME)<br />
ProductID (INT)<br />
AmountOrdered (INT)
So I want to write a query that will show me the information from this table on the first order for a specific product (let's say id 123) received by every customer.
The following query will get me almost there:
SELECT CustomerID, MIN(OrderPlaced)
FROM Orders
WHERE ProductID = 123
It only gets me almost there though because notice how the AmountOrdered field is missing from the query and unless it's part of an aggregate function I can't add it. I can add it with a subquery but that is where the query loses its elegance rapidly, especially considering that the real world tables I'm dealing with usually have more than just one or two extra columns.
Any ideas?
|
|
|
|
|
Almost all your solutions using an aggregate will require a sub query, there is nothing inelegant about using one!
You can also look into ROW_NUMBER and PARTITION.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Thanks. I've been shying away from Over() , ROW_NUMBER and Partition By because they're rather Microsoft specific.
I agree, generally there's nothing inelegant about using a subquery but in this particular case it is anything but elegant.
Consider the table in my example and let's say there are a few more columns:
ContractID (INT)<br />
OrderSource (INT)<br />
AgentID (INT)<br />
ProvinceID (INT)<br />
DeliveryMethod (INT)
So, in order to get what I want, using GROUP BY and subqueries, it would end up looking something like this:
SELECT
CustomerID,
MIN(OrderPlaced),
FROM Orders
WHERE ProductID = 123
GROUP BY CustomerID
I'm sure you'll agree that the above query is pretty much the antithesis of elegance.
modified 27-May-13 4:18am.
|
|
|
|
|
No no no you want the ID of the record for each customers earliest order (I hope) so first create a query that gets you that order ID, probably add the orderID to the above query.
Make sure the IDs are the expected results before moving on to the next stage.
Now wrap that query in a
Select * from Orders
where orderID in (Your innerquery)
or if there are multiple fields in your inner query use a join
Select *
From Orders
inner join (Yourinnerquery) X on X.orderid = orders.orderid
You can make the inner query as complex as required but it should return the minimum required to join to your field table (Orders presumably)
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
BINGO! You've hit the nail on the head. Thanks. Here is the query that does that:
SELECT *
FROM Orders
WHERE OrderID IN (
SELECT (
SELECT TOP 1 OrderID
FROM Orders O2
WHERE CustomerID = O1.CustomerID
ORDER BY Inserted
)
FROM Orders O1
GROUP BY CustomerID
)
Of course this query relies on the existence of OrderID , a primary key of the Orders table. I didn't define it in my original question but just about every table should have a primary key anyway and just about all my tables usually do
The great thing about this query is that the outermost query can have a SELECT * and, as you say, could even join the Orders table with any other table that might contain linked information on the orders.
Thanks again. It might seem insignificant but you've just helped me solve a problem I've been grappling with for years and never really bothered to definitively put to bed.
|
|
|
|
|
You are definitely welcome, once you get your head around SQL it can be very rewarding making the dammed thing do what you want. Then the bastards introduce a new way of doing something (CTEs come to mind) and you have to start all over again!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
<edit>low on caffeine => dysfunctional brain</edit>
Be excellent to each other. And... PARTY ON, DUDES!
Abraham Lincoln
modified 27-May-13 17:15pm.
|
|
|
|
|
Jörgen Andersson wrote: I believe one subquery is unnecessary. Try:
SELECT *
FROM Orders
WHERE OrderID IN (
SELECT TOP 1 OrderID
FROM Orders O1
GROUP BY CustomerID
ORDER BY Inserted
)
I'm not sure I understand that inner query. For one OrderID in the SELECT clause should surely be part of an aggregate function seeing as it is not in the GROUP BY clause. Also, for Inserted to be contained in the ORDER BY clause it will also have to be part of an aggregate function. What am I missing?
|
|
|
|
|
You're not missing anything, it's me having had to little coffee and a non-functional brain.
Sorry 'bout that.
Be excellent to each other. And... PARTY ON, DUDES!
Abraham Lincoln
|
|
|
|
|
Hi
I had installed SSE2008 on a Small business 2008 server.
There were two of these servers on the domain.
The server I installed on was not the main server (if that makes sense)
In any case, they reinstalled the main server, but now I cannot start the SQLSERVER agnet service. The way I understand it, when you install an instance of SSE, there are certain windows permissions set up, and now since they re-installed Small Business server, thers permissions are no longer valid. I can go into the SSE server using Management Studio, but my appplication cannot see the server. Previously whet the server was rebooted, my application also could not see the server, but then by starting the service: SQLAgent$SQLEXPRESS it worked.
Any ideas how I can fix this? (I assume re-installing a new instance of SSE woulod work, since it would create new windows accounts? But this seems like the long way around and not a very elegant solution?)
|
|
|
|
|
We have 900,000 veterans with claims in the VA. It's clear the government either cannot or will not solve this, but it needs to be solved.
I wonder one thing: is there a way to crowdsource the solution?
There are some brilliant developers and data analysts on this board. While I don't count myself among these luminaries, I feel that we could solve this.
Cheers,
Daaron
|
|
|
|