I have the following query, the relationship is mutiple pictures per dog and multiple dogs per registered User. the query below will return dogs that belong to users that have not expired. the problem is that some users have many dogs and other users only have one dog listed, the query below will return a record for every dog. What I would like to do is return a random dog per user and only one dog per user each time the query executes. therefore if I have 10 users and 50 dogs I would like my quesry to only return 10 dogs one beloinging to each user, and the next time the quesry executes it would be nice if it once again return 10 dogs but a different 10 dogs 1/per user where it was able..
I need to excute one insert query basend on two different if conditins. If one of them conditions is true then excute block of code.
For Example,
if exists( select * from tablename where docid = @docid and adv_feed <> 'sent' ) or if not exists (select * from usaa_audit_fields_log where docid = @docid) begin insert statement end
I have tried using OR statement between them but it doesn't work.
Is there any possibility to execute the job in sql server. I want to create the Job. then through the quer i want to execute this Job by passing parameters. can we able to do this.Actucally i want to execute the SP from front end. but suddenly it should respond to the page. but that SP will run for nearly 5 minutes.
I am getting frustrated with this problem, I dont know what i did, but now I cannot execute any stored procedured when I could last time.When I use my asp.net application to run the query, it finds the stored procedure but when I execute it is sql management studio it says it cannot find the stored procedure even though it is there.I tried to execute other procedures and the samething happens. Even when I try a simple query it says it cannot find the tableI could execute the query if i placed Use [databasename] in front, but even with this, I cannot execute stored procedures.
i want to get first picture of any album in photo table. i want get output table for show to the datalist control.i need to get albumid in output
so i create a sproc similar this:
create PROC USP_GETFirstPhoto @ALBUMID INT OUTPUT, @CATEGORY NVARCHAR(50) OUTPUT , @CAPTION NVARCHAR(50) OUTPUT AS SELECT @ALBUMID = A.AlbumID,@CATEGORY=A.Category,@CAPTION=TMP.Caption FROM Albums A CROSS APPLY ( SELECT top 1 * FROM Photos WHERE AlbumID=A.AlbumID )TMP order by A.AlbumID DECLARE @x INT,@y NVARCHAR(50),@z NVARCHAR(50) EXEC USP_GETFirstPhoto @x output,@y output,@z output select @x,@y,@z
but when i exec this proc i have a recorde not a result set
with this query i have resultset
SELECT * FROM Photos CROSS APPLY ( SELECT TOP 1 AlbumID FROM Photos GROUP BY AlbumID)TMP
I am looking through a sql stored procedure which I might need to update in the near future. Basically the stored procedure is about 20 lines long. The stored procedure first builds a query
and stores it in a variable named "@Sql". And then for the last two lines of the stored procedure it appears that the big sql statement stored in "@Sql" is executed by using the "EXEC" command. See below. What is confusing though is that the query appears to be exectuted twice? Why was the query written in this way. Don't both lines do the same thing? Why is it being done twice? Could this possibly be a mistake on the part of the person who wrote the query. Below are the two lines I am talking about?
1. I have a GridView on my page and it uses sqldatasource with parameterized query. What I want to do is, on page load (where nothing has been selected so no parameter supplied), I want it to query everything (something like SELECT * FROM [this_table]) but since my SelectCommand is something like
SELECT * FROM [this_table] WHERE [this_column] = @someParameters AND [that_column] = @someParameters.
Can I play around with default value to achieve something like that but how ? Now, when the page loads, it doesn't show anything (No Gridview).
2. On my page, I made something like (username, gender, address, and more) and one single search button. That means, no single control enable auto postback. What I am trying to accomplish is building dynamic query
(if username specifed -> SELECT * FROM [this_table] WHERE [username] LIKE @username).
If both username and gender are specified (SELECT * FROM [this_table] WHERE [username] LIKE @username AND [gender] = @gender) and you know the rest. How can I do this using GridView and SqlDataSource ? To my knowledge, I can only specify one SELECT statement in a sqldatasource.
I need to run the HttpContext.Current.Server.Execute method in my ASP.NET application. This application has a WCF operation that does some processing. Currently, I am to do my processing correctly from within my WCF operation. However, I would like to do this asynchronously.
In an error to attempt this asynchronously, I tried running Server.Execute in the DoWork event handler of a BackgroundWorker. Unfortunately, this throws an error that says
"object reference not set to an instance of an object" The HttpContext element is not null. I checked that. It is some property nested in the HttpContext object that appears to be null. However, I have not been able to identify why this won't work. It happens as soon as I move the processing to the BackgroundWorker thread. My question is, how can I asynchronously execute the Server.Execute method?
if (textbox1) has contain some value i need to execute some query and like this i need to check if textbox2 is contain some value and textbox1 is contain some value then i need to execute query based on textbox2... now we left query which has on textbox 1 coz now textbox 2 has value and like this i need to check if textbox3 is contain some value and textbox2 is contain some value and textbox1 is contain some value then i need to execute query based on textbox3...now we left query which has on textbox 1 and 2 coz now textbox 3 has value.
i need to check if textbox4 is contain some value and textbox3 is contain some value and textbox2 is contain some value and textbox1 is contain some value then i need to execute query based on textbox4...now we left query which has on textbox 1 and 2 and 3 coz now textbox 4 has value.
i need to check if textbox5 is contain some value and textbox4 is contain some value and textbox3 is contain some value and textbox2 is contain some value and textbox1 is contain some value then i need to execute query based on textbox5...now we left query which has on textbox 1 and 2 and 3 and 4 coz now textbox 5 has value. so let me know how to achieve this.
I'm building a web app for my company that will run a query every few seconds against SQL Server, and the data that it returns is which database is restoring and how much % complete it is. I have the query already set up and it works fine.
What I want to do is on my Web Form, have a "div" element that will contain the % complete of a database restore, and have it update every few seconds using the JavaScript timer object:
setInterval(function, interval)
I figure I would need to use XMLHttpRequest to send the request to the web server which will run the SQL query. Am I on the right track? How would I even start to do this?
My SQL query is below:
Use master Select der.session_id, der.command, der.status, der.percent_complete, * From sys.dm_exec_requests as der Where percent_complete > 0
I have table for past four years. It had a records for around 10 Lacks it was taking lot of time to execute so i removed recordes from the table. Table size was reduced to 29 thousand. Still when i execute a query from my application it takes more than 2 minutes to return.
I am trying to loop throug multiple sql server instances (connections) and execute one query for all those connections and ouput in one grid.I am using checkboxes to show all of my connections. So far i have the following code: ( but the code only just executes the query on the first selected instead of the 2 or more selected connections.
Sub executesqlquery() Dim instance As String Dim instance1 As String [code]....
I am having a meltdown over something that seems so simple and yet isn't working. Here's my scenario.
I have an object structure of tEvents, which contains properties of an event like a run of concerts. tEvents in turn contains an entity set of tEventOptions, which include properties like EventDate, Cancelled etc. I would like to query a list of tEvents using properties of the tEventOptions, for example filtering by date.
My pageis using a calendar object to show event dates. So I am trying to find if any tEvents in the List coming back from the database match the date of the day element being rendered in my Calendar control like so (in this snip 'data' is List and results from a db query):
[code]....
Except r, my query result var, is always true no matter what data it receives. I have tried the sub query using other properties of tEventOption and get the same 'true' result each time. I know that the data does not reflect this result so I clearly have a problem with the structure of my query, but for the life of me I cannot find a way to resolve it.
i made one window base application in VS2008 (VB.net). i made one simple code where i can insert data.and after inserting i can see that data on grid.when i am inserting data insert query runs perfect.after that for debugging purpose i fire select query and get result in dataset and its show data too.but when go into database my inserted data not showing there.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim con_str As String = "Data Source=.SQLEXPRESS;AttachDbFilename=|DataDirectory|Database1.mdf;Integrated Security=True;User Instance=True" Dim con As SqlConnection = New SqlConnection(con_str) Dim cmd, cmd2 As SqlCommand Dim adp As New SqlDataAdapter.....
basically i have two dropdown boxes to filter data and textbox with stored procedure bound to gridview.i want to be able to query data depending on the selected value passed,either using one or more parameter values.
i would like seperate sqlcommands to chose from depending on which controls i select to pass parameters.
i have included a parameter Select(control id) as this is declared by the wizard for stored procedure.
but i am not sure how it is defined on the page and passed to procedure.
I need to know how to display the result of a select query in a datagrid or GridView with VB.NET?
Consider SELECT * FROM some_table. I don't know what columns the table has. Is there a way to just output the result to a table, with a dataset for example?
I have a query which returns multiple columns from the database using LINQ
var donors = from d2 in db.Donors where d2.Status == "Pending" select new { donorID = d2.donorID, bloodGroup = d2.bloodGroup, contactNo = d2.contactMobile, status = d2.Status };
now I want to display the results in different Labels accessing one column value from donors resultset.
ex:
Label1.Text = donorID; Label2.Text = bloodGroup; ...and so on
I have very long select query which i need to filter based on some params, i'm trying to avoid having different stored procedures or if statements inside of single stored procedure by using partly dynamic TSQL.I will avoid long select just for example sake
select a from b where c=@c or d=@d
@c and @d are filter params, only one can filter at the same time but also both filters could be disabled. 0 for each of these means param is disables so i can create nvarchar with where statement in it...
How do i integrate in here dynamic query so 'where' can be added to normal query. I cannot add all the query as big nvarchar because there is too many things in it which will require changes ( ie. when's, subqueries, joins)