Use The Current Username For Filtering In SQL Statement
Dec 2, 2005
My objective is to only get the records for Current USER's region and district. Please let me know
what I am missing....Thank you!!!
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
bindGrid();
}
}
private void bindGrid()
{
@username=HttpContext.Current.User.Identity.Name;
SqlCommand getCommand = new SqlCommand();
getCommand.Connection=sqlConnection1;
getCommand.CommandText="SELECT DealerCode,DealerName,ClaimCount," +
"Total$,CliamDays FROM DealerList,pwausers,pwadlrs WHERE" +
"@username=user_name AND parts_reg=dmpreg AND parts_dist=dmpdist";
sqlConnection1.Open();
sqlDataAdapter1.Fill(dataSet1);
DataGrid1.DataSource=dataSet1;
DataGrid1.DataBind();
Cache["DealerListData"]=dataSet1;
sqlConnection1.Close();
}
View 2 Replies
ADVERTISEMENT
Aug 6, 2015
At the following MDX code , I want to get the aggregate of measure only for members that are also in the specified last time (like in examp 01/06/2015) . I tried existing and exists, but without any lack.
WITH MEMBER A AS
(b)+(C)
MEMBER [Measures].[Aggregate] AS
Aggregate(DAYTIME].[Month].&[2013-01-01T00:00:00]:[DAYTIME].[Month].&[2015-06-01T00:00:00],
([Measures].[D])
[Code] ....
View 13 Replies
View Related
Jun 15, 2006
Hi!
Im making a page where I want to display this weeks information & news as a default setting.
What do I have to do to make it work (Im new to .Net but used to ASP 3 & MySql)?
My idea is to store the week number in a variable which is updated att Page_load and thento use this variable in the following sql statement that gets news and info from the MsSqldatabase where weeknumber is = the defined variable.
So how do I store weeknumber in a variable?ANDHow do I use this variable in the SQL statement?
View 1 Replies
View Related
Sep 2, 2015
Below is the SQL Query i am currently having
SELECT IG_FinancialTransactionSummary.ClaimNum,IG_FinancialTransactionSummary.TransactionCode,
IG_FinancialTransactionSummary.TransactionDate,IG_FinancialTransactionSummary.Username,
FinancialTransactionSummaryTest.ClaimNum,FinancialTransactionSummaryTest.TransactionAmount,
FinancialTransactionSummaryTest.UserName--,FinancialTransactionSummaryTest.TransactionDate
[Code] ....
And here is the result dataset
ClaimNumTransactionDateUsername ClaimNum TransactionAmountUserName
2000074 20150209jerry.witt 2000074 -10000DATAFIX INSERTED ON 20150626 AT 162152493 LOCAL
2000074 20150626DATAFIX INSERTED ON 20150626 AT 162152493 LOCAL 2000074 -10000DATAFIX INSERTED ON 20150626 AT 162152493 LOCAL
[Code] .....
So,if we look at the result set, we notice 2 conditions where the IG_FinancialTransactionSummary.Username is like 'Data' and if we see the transaction date then sometimes that is the max transaction date or sometimes there are transactions that happened after but that doesn't have like '%data%' in username . So, i need to add a new column to my sql query which should basically verify if the username is like '%data%' and if that is the max(transaction date) or even if there are any transactions after that doesn't have like '%data%' then YES else No.
View 13 Replies
View Related
Apr 27, 2007
Hi
Hope somebody can help me with a problem that i am having. I have the following piece of code
<%
Dim sqlConn As SqlConnection
Dim sqlCmd As SqlCommand
Dim sqlReader As SqlDataReader
sqlConn = New SqlConnection("server=myserver;database=aspnet;uid=username;pwd=password")
sqlCmd = New SqlCommand("SELECT SamAccount, FirstName, Surname, FirstName + N' ' + Surname+' Logged In ' AS UserLoggedIn FROM tblUsers WHERE (SamAccount = " + Request.ServerVariables("logon_user") + ")", sqlConn)
sqlConn.Open()
sqlReader = sqlCmd.ExecuteReader()
%>
<%
Dim strPCNAme As String
sqlReader.Read()
strPCNAme = sqlReader("UserLoggedIn")
Response.Write(strPCNAme)
%>
The bit i have i have underlined and made bold throws up the error. Basically what i am trying to do is to filter the the SQL statement by the server variable logon user. Everthing works fine until the point that i put the where clase in.
Can anybody help please?
Thanks
Marcus
View 2 Replies
View Related
Aug 21, 2014
How I am using a CASE statement within a WHERE clause to filter data:
CREATE PROCEDURE dbo.GetSomeStuff
@filter1 varchar(100) = '',
@filter2 varchar(100) = ''
AS
BEGIN
SELECT
[Code] .
What I want, is to be able to pass in a single value to filter the table, or if I pass in (at the moment a blank) for no filter to be applied to the table.
Is this a good way to accomplish that, or is there a better way? Also, down the line I'm probably going to want to have multiple filter items for a single filter, what would be the best way to implement that?
View 5 Replies
View Related
Sep 25, 2001
My backup fails in the night, because of a non logged operation being executed at the same instant. I am interested in finding out the statement that is causing the problem. What would be the best way to do that?
View 2 Replies
View Related
Jul 20, 2005
I received this error message in the application event logs. Can anyone tell me what this is pertaining to?Error: 7102, Severity: 20, State: 99SQL Server Internal Error. Text manager cannot continue with currentstatement.Thanks Barb
View 2 Replies
View Related
Nov 12, 2014
I was using Type 2 for one of our Fact table.... and need to put a flag to know which one is the Current record... I couldn't able to figure how to implement logic in the merge statement... This is an example Query ....I was using like this for my fact table...
Basically I need to track CustomerName and City... So I need a Currentflag (Y) for latest record....
MERGE INTO [dbo].[TargetCustomer] AS TRG
USING [dbo].[MyCustomers] AS SRC
ON TRG.[CustomerID] = SRC.[CustomerID]
AND TRG.[CustomerName]=SRC.[CustomerName]
AND TRG.[City]=SRC.[City]
[Code] .....
View 7 Replies
View Related
Jun 29, 2006
I have a db that has duplicate customer records.
If I run the following select statment against the appropriate table it returns the duplilcate records in the result set. However, from this list I want to add an additional select statement embedded into the query that will actually return only those records with the most current syscreated date.
Example of script I'm using---
select cmp_fadd1, syscreated, cmp_name, cmp_code
from cicmpy
where cmp_fadd1 in (select cmp_fadd1
from cicmpy
group by cmp_fadd1
having count(1) = 2)
order by cmp_fadd1,syscreated desc
The results is:
Address Syscreated date Customer
1622 ONTARIO AVENUE 2005-06-15 22:19:45.000 RELIABLE PARTSLTD
1622 ONTARIO AVENUE 2004-01-22 18:10:05.000 RELIABLE PARTS LTD
PEI CENTER 2006-01-05 22:03:50.000 P.G. ENERGY
PEI CENTER 2004-01-22 17:57:56.000 P.G. ENERGY
From this I want to be able to select ONLY those records with the most current syscreated date or those records with 2005-06-15 and 2006-01-05
Can anyone help me with creating this?
Thanks
Cyndie
View 4 Replies
View Related
Jun 2, 2014
I put this together to export the user name /password to a csv file to test my SP to output the user name/password.
DECLARE @user_name varchar(50)
DECLARE @psswrd varchar(10)
SELECT @user_name ,@psswrd
FROM ngweb_bulk_enrollments
EXEC master.dbo.xp_cmdshell 'bcp NGDevl.dbo.ngweb_bulk_enrollments out C: est.csv -Sserver1 -T -t, -r
-c'
This works but I don't get the headers in the file. How can I include the headers?
View 7 Replies
View Related
Feb 3, 2015
I'm trying to create a WHERE statement that will calculate values from our current fiscal year to the last complete month.I'm using code that was created for us that does the calculations for our entire fiscal years. I thought I had fixed the WHERE statement to work like we wanted last year, but it appears to be broken now after trying it again in January and February. I'm guessing my WHERE statement only works for March and up, but how to get it to work for every month. Most attempts I'm trying it's just returning very large and inaccurate values.
I included my WHERE statement below of what I originally had that worked last year. The @BeginYear/Month/etc are retrieved from a different table and @Month is just set to MONTH(GETDATE())-1.
WHERE
(YEAR(SA3.DocumentDate)=@BeginYear AND MONTH(SA3.DocumentDate)>=@BeginMonth AND MONTH(SA3.DocumentDate)<=@Month)
OR
(YEAR(SA3.DocumentDate)=@EndYear AND MONTH(SA3.DocumentDate)<=@EndMonth AND MONTH(SA3.DocumentDate)>=@Month)
View 6 Replies
View Related
Sep 21, 2006
When my production server processing some queries suddenly the SQL Server service crashed and following error was in the error log:
SQL Server Internal Error. Text manager cannot continue with current statement.
The server is running SQL Server 2000 with SP4.
I am really concerned because this is a production sever and there are over 300 users access concurrently.
Please help me to find a solution.
Thanks,
Roshan.
View 8 Replies
View Related
Jun 8, 2008
I've this query
SELECT
t1.ID, t1.Date, t1.Time,
t1.VALUE
FROM RESULT WHERE t1.Date>=CONVERT(VARCHAR(10),DATEADD(d,-7,GETDATE()),101) AND
t1.Date<CONVERT(VARCHAR(10), GETDATE(), 101)
Let's say, current date is 8 AUG 2005 and current time is 2045
So, i will get
ID | Date (this is datetime) | Time (this is integer) | Value
--------------------------------------------------
204 | 8/1/2005| 2359 | 90
205 | 8/1/2005| 2250 | 99
206 | 8/1/2005| 1950 | 88
...
...
207 | 8/7/2005| 1845 | 77
208 | 8/7/2005| 2255 | 77
209 | 8/7/2005| 2140 | 77
Can someone can show me to filter data between
t1.Date>=CONVERT(VARCHAR(10),DATEADD(d,-7,GETDATE()),101) AND TIME>=CurrentTime
t1.Date<CONVERT(VARCHAR(10), GETDATE(), 101) AND TIME<=CurrentTime
If current date is 8 AUG 2005 and current time is 2045, so the result shown as follow
ID | Date (this is datetime) | Time (this is integer) | Value
--------------------------------------------------
204 | 8/1/2005| 2359 | 90
205 | 8/1/2005| 2250 | 99
...
...
207 | 8/7/2005| 1845 | 77
I only have this query,
SELECT
t1.ID, t1.Date, t1.Time,
t1.VALUE
FROM RESULT WHERE t1.Date>=CONVERT(VARCHAR(10),DATEADD(d,-7,GETDATE()),101) AND
t1.Date<CONVERT(VARCHAR(10), GETDATE(), 101)
lack of idea to put the TIME condition.
Plz help me..
View 14 Replies
View Related
Aug 6, 2006
With the function below, I receive this error:Error:Transaction count after EXECUTE indicates that a COMMIT or ROLLBACK TRANSACTION statement is missing. Previous count = 1, current count = 0.Function:Public Shared Function DeleteMesssages(ByVal UserID As String, ByVal MessageIDs As List(Of String)) As Boolean Dim bSuccess As Boolean Dim MyConnection As SqlConnection = GetConnection() Dim cmd As New SqlCommand("", MyConnection) Dim i As Integer Dim fBeginTransCalled As Boolean = False
'messagetype 1 =internal messages Try ' ' Start transaction ' MyConnection.Open() cmd.CommandText = "BEGIN TRANSACTION" cmd.ExecuteNonQuery() fBeginTransCalled = True Dim obj As Object For i = 0 To MessageIDs.Count - 1 bSuccess = False 'delete userid-message reference cmd.CommandText = "DELETE FROM tblUsersAndMessages WHERE MessageID=@MessageID AND UserID=@UserID" cmd.Parameters.Add(New SqlParameter("@UserID", UserID)) cmd.Parameters.Add(New SqlParameter("@MessageID", MessageIDs(i).ToString)) cmd.ExecuteNonQuery() 'then delete the message itself if no other user has a reference cmd.CommandText = "SELECT COUNT(*) FROM tblUsersAndMessages WHERE MessageID=@MessageID1" cmd.Parameters.Add(New SqlParameter("@MessageID1", MessageIDs(i).ToString)) obj = cmd.ExecuteScalar If ((Not (obj) Is Nothing) _ AndAlso ((TypeOf (obj) Is Integer) _ AndAlso (CType(obj, Integer) > 0))) Then 'more references exist so do not delete message Else 'this is the only reference to the message so delete it permanently cmd.CommandText = "DELETE FROM tblMessages WHERE MessageID=@MessageID2" cmd.Parameters.Add(New SqlParameter("@MessageID2", MessageIDs(i).ToString)) cmd.ExecuteNonQuery() End If Next i
' ' End transaction ' cmd.CommandText = "COMMIT TRANSACTION" cmd.ExecuteNonQuery() bSuccess = True fBeginTransCalled = False Catch ex As Exception 'LOG ERROR GlobalFunctions.ReportError("MessageDAL:DeleteMessages", ex.Message) Finally If fBeginTransCalled Then Try cmd = New SqlCommand("ROLLBACK TRANSACTION", MyConnection) cmd.ExecuteNonQuery() Catch e As System.Exception End Try End If MyConnection.Close() End Try Return bSuccess End Function
View 5 Replies
View Related
Apr 25, 2008
Hi,
I'm making some sort of application where people can add their resume.
They also need something to add places where they have worked or currently are working.
I have a form where they can add this and i add this experience using the following stored procedure:
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create procedure [dbo].[sp_Insert_Experience]
@ExperienceId uniqueidentifier,
@ExperienceEmployee nvarchar(100),
@ExperienceFrom datetime,
@ExperienceUntil datetime,
@ExperienceQualifications nvarchar(250),
@ExperienceTechnologies nvarchar(250),
@ExperienceTasks nvarchar(250)
as
insert into Experiences
values(@ExperienceId,@ExperienceEmployee,@ExperienceFrom,@ExperienceUntil,@ExperienceQualifications,
@ExperienceTechnologies,@ExperienceTasks);
It must be possible to add the place where they currently are working. Then the ExperienceUntil has to be something like still going on. Then I decided that the user then had to set the current date.
But what I want is the following, I want that the ExperienceUntil keeps updating automatically, like everytime i get that record, it has to have current date.
Is this possible ?
But if the ExperienceUntil isn't the current date , it just had to take the supplied parameter date.
View 7 Replies
View Related
Feb 21, 2002
Hi!! I use nt groups to give access to users. I need to now the name of the user who is connected to a especific database.
I tryed with suser_name() function but it returns null value because ntgroups are used.
if someone now any function that can help me, i will appreciate your help.
Thanks.
View 1 Replies
View Related
Jan 26, 2008
I just installed SQL 2005 Server. I am using SQL Server 2005.
Why do I have to login with the username with "sa"?
I failed to sign in with other usernames.
What is the trick?
Thanks
View 3 Replies
View Related
Jul 8, 2007
A beginner's question I'm sure. When visitors have logged into my site, how do I then use their UserName as a parameter in an SQL WHERE clause so that I can pull up their detailed information. I'm using VB if additional code is required.
Thanks in advance.
View 2 Replies
View Related
Oct 4, 2005
I built an eommerce site on my local computer at work. It's now time to
put the site on our server and get things rolling... anyways, I'm
trying to perform an sqldump so I can gather the appropriate text files
so I can upload the database. Anyways, the sqldump program I am
using requires a username and password to access the sql database.
I am using MSDE and have no clue as to what the username and password may be....
My VisualStudio .Net automatically connects when I work on the site.
Does anyone know what the default username and password may be or what my options are to get this sqldump to work?
Any help would be appreciated.
View 2 Replies
View Related
Jul 10, 2001
Hello out there in SQL land! I'm writing a T-SQL script to create tables and grantlogins to local machine NT accounts. The problem is that I'm sending this script out to about 1700 machines with 1700 different DomainNames!
So hard-coding the domainusername is NOT an option. In other words, non-networked computers. In the T-SQL command:
EXEC sp_grantlogin [DomainUsername]
-OR-
EXEC sp_grantdbaccess [DomainUsername]
note: Domain= @@SERVERNAME
Username = Jib
I want to have a variable of some sort pass the DomainName & concatenated username in order to grant login the SQL Server for the NT user. Any help would be greatly appreciated.
Thanks!
View 1 Replies
View Related
Aug 1, 2006
hey can anyone suggest me how to write the efficient( a bit faster) stored proc to generate alternative usernames( with logical variations like the one of hotmail ) if provided one is already present in database... :)
View 5 Replies
View Related
Dec 13, 1998
how do you send SQL Server the proper username and password in ASP Scripts?
So far, I have: Connection.Open "DSN=DSNname;pwd=password"
Where does username play in all this and what is its format.
Appreciate any help....
View 2 Replies
View Related
Aug 9, 2004
Hi everybody,
Here the environment is application in 3 layers.
So the user in his client machine, access the application in an application server that sends the request to my sql server database server.
My problem is: when I run sp_who from Query Analyzer, I see the host name that is pre-defined inside code application. But, actually, I need to know the user who is requesting the transactio so I can know right the person who is slowing my database performance....
Do you know, any function, procedure or anything else that I can use in the application code in order to provide the user or the host name from the client machine?????
I hope some answers...
Thank you all,
View 7 Replies
View Related
Jan 6, 2005
Hello
Currently, I am using a varchar "UserName" as a primary key instead of an Identity or GUID.
System Info:
When user's sign up they provide the "UserName" that is used as a PK.
Creating a message board type web application.
UserNames will never change.
UserNames are used extensively as FK's in other Tables.
We want to scale well.
Does anyone know the implications?
I understand Joins are faster on numerical values than strings but we will not be performing many joins.
In my case is it better to use Identity as a PK or is it better to use a varchar for a "Users" table?
Thanks
jenn
View 1 Replies
View Related
Apr 25, 2008
Hi all,
I want create a trigger that will log all modification to a table.
I need to identify the username that modified the data.
Here is my problem :
- they are connected to a Terminal Server so stationName il always TSName
- They are using an application I cannot modify that always use the same login information using SQL authenticationMode
So I need to be able to get their Windows session Username.
Is there any way I can do that in my trigger ?
Thanks
View 5 Replies
View Related
Apr 22, 2006
Hi, I hope this is the right place to post this. I am pretty much stuck but think I am doing pretty good so far as I am getting more and more into SQL
using SQL Server 2000 here.
I want to be able to get the last username who replied to a topic. The "DateOfLastReply" works great, it gives me the last date of a reply to a topic so pretty much along with this, I want to get who it was that replied last. Any ideas? so far, I have this but it isnt correct:
SELECT Threads.[ID] 'ThreadID', ThreadName, DateOfCreation 'DateCreated',
(SELECT TOP 1 DateOfReply FROM Replies WHERE Replies.ThreadID = Threads.[ID] ORDER BY DateOfReply DESC) 'LastReplyDate',
(SELECT TOP 1 e.Username FROM Replies, Threads WHERE Replies.UserID = e.[ID] AND Threads.[ID] = Replies.ThreadID AND Threads.ThreadStarterUser = e.[ID] ORDER BY DateOfReply DESC) 'LastUserReplied', --HERE
(SELECT COUNT(ReplyID) FROM Replies WHERE ThreadID = Threads.[ID]) 'NumberOfReplies',
e.username 'UsernameCreator'
FROM Threads
INNER JOIN Users e ON
e.[ID] = ThreadStarterUser
View 6 Replies
View Related
Jul 11, 2007
VB ASP.NET 2.0
How do I get the Authenticated UserName passed to a Select Command of a data control ?
I'm not clear on how to get the logged in username from User.Identity.Name as a string or how to pass it to the Select Command of a control.
I've had some success with SelectParameters / ControlParameter's in the Master Control context, but otherwise I don't understand how to create a Parameter for use with the SQL.
I want to show the user data from a database, based on who is logged in .
Help, greatly appreciated.
Chris
View 8 Replies
View Related
Aug 16, 2004
how can i change the username of SQL Server 2000 from sa to another username?
thank you for the help and for the time
View 7 Replies
View Related
Jan 1, 2005
Hi,
I have installed MSDE using the following parameter:
commandline> setup SAPWD="MySAPwd"
now all was set up... when i opened the osql utility..i wasnt able to login... it kept asking me the login name ans password...
i entered my windows login name which is 'home' and entered 'kham00s' as the password... it didnt work... then i entered my windows login name again which is 'home' and entered 'OTHERPASSWORD' as the password which is my system password...but did not work either...
then i logged in using :
commandline> osql -E
It successfully logged in... and i was able to create databases and tables...
can someone tell me how to set a username and password for MSDE please... so that i can connect to MSDE using WebMatrix...
i m coming from a PHP/MySQL background so i know SQL and stuff... but dont know how to handle and configure MSSQL...
waiting for the response..
thanks in advance...
Bye.
Kamran.
View 6 Replies
View Related
Jan 11, 1999
I want to establish logging using NT Security. The problem is that user names in NT have underscore(_). When I establish NT Scurity in SQL security manager, SQL Server tries to add blank names as login id and they will not go through. Is it manadatory to remove underscore from username?
Because of structrual hierarchy, I have different groups in NT to be mapped to SQL Server groups and each group has different permission on SQL tables. In some cases we might have same users in more than one group. I read that it is not possible if you use NT integrated security. Is there any thing that can be worked around this and is this problem still exists in SQL 7.
Janne Hakulinen gave me a reply (Appreciate that) but when I did as he said, I got no success. So I am asking him to reply me at alim@goldline.net and let me send him an e-mail.
Thank you in advance
Ali Malekshahi
View 1 Replies
View Related
Aug 16, 2000
I need to get into a database and need the password and username for a Microsoft SQL Server v.6.5 database. Can you help or do you know someone else who can? This database is owned by us and this is a "legal" project.
Thank you.
Michael A. Wise
Manager, MIS/IT
EBARA International Corporation
Cryodynamics, Electric Motor, Standard Pumps Divisions
"World's Leader in Liquefied Gas Pumps and Turbines"
350 Salomon Circle
Sparks, Nevada, USA 89434
775-356-2796, xt. 215; FAX: 775-356-2884
mailto:mwise@ebaraintl.com
www.ebara.co.jp/indexe.html
www.ebaratech.com
www.pumpsebara.com
View 1 Replies
View Related
May 23, 2006
Hi I've created a login in my SQL Server 2005 like this:
CREATE LOGIN testuser
WITH PASSWORD = 'TestPWD';
USE DB1;
CREATE USER testuser FOR LOGIN testuser;
GO
now i want to connect from a c# app with the following connection STring
"Data Source=TURM21;Initial Catalog= Db1; Database= Db1 ; USER = testuser; PASSWORD = TestPWD; pooling=false; "
and i get the following Exception:
SqlConnection Handle : System.Data.SqlClient.SqlException: A connection was successfully established with the server, but then an error occurred during the login process. (provider: Shared Memory Provider, error: 0 - No process is on the other end of the pipe.)
CAn somebody help me? Whats wrong? Is it my connection string?
Greetz
View 2 Replies
View Related