I would like to know if there is anyway I can set one of my stored procedure parameter as optional. Answer Providing a default value to the stored procedure parameter will make it optional. EDIT: CREATE PROC [ EDURE ] [ owner. ] procedure_name [ ; number ] [ { @parameter data_type } [ VARYING ] [ = default ]
Tag: sql
How to implement a do-while loop in tsql
I’m trying to figure how to implement this in TSQL The only iterative control flow sentence provided by Transact-SQL is while (condition) sentences that first evaluates the condition and if that condition is true then execute the sentence. I’m thinking in a scenario like execute a UPDATE statement…
How to make a SQL query for last transaction of every account?
Say I have a table “transactions” that has columns “acct_id” “trans_date” and “trans_type” and I want to filter this table so that I have just the last transaction for each account. Clearly I could …
How to count occurrences of a column value efficiently in SQL?
I have a table of students: I want to query for all students, and an additional column that counts how many students are of the same age: What’s the most efficient way of doing this? I fear that a sub-query will be slow, and I’m wondering if there’s a better way. Is there? Answer This should…
T-SQL – Aliasing using “=” versus “as” [closed]
Closed. This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 3 years ago. This post was edited and submitted for review last month and failed to reopen the post: Ori…
PHP MySQL INSERT return value with one query execution
Is there anything returned from MySQL/PHP on a INSERT query being executed? Here is my function which I have in a CLASS. This is how I call the function But executing a INSERT query the $rs returns nothing. Does my function need help or is this the default behavior? Any tips would be helpful as well. Answer I…
Combining OUTER JOIN and WHERE
I’m trying to fetch some data from a database. I want to select an employee, and if available, all appointments and other data related to that employee. This is the query: SELECT TA.id, TEI….
How to add a Try/Catch to SQL Stored Procedure
In this proc how can I handle try catch for exception? Answer See TRY…CATCH (Transact-SQL)
Counting DISTINCT over multiple columns
Is there a better way of doing a query like this: SELECT COUNT(*) FROM (SELECT DISTINCT DocumentId, DocumentSessionId FROM DocumentOutputItems) AS internalQuery I need to count the number of …
Changing INT to BigInt
I have a warehouse table with 16 tons of data in it. I have a few Integer columns in it. We have to cast these into BIGINT for every query we write, because the SUM is too large to fit in an INT. We now have a new datamart under development. So we thought, why not change all these columns