Good Day everyone! I’ve been searching everywhere on how to get a specified query using if-else statement inside a single stored procedure but still no luck on how to achieve those function. Here’s the T-Sql When exec command is called, it only return Command(s) completed successfully instead the value/table of the selected command. Since the @action is null, it should
Tag: stored-procedures
A better way to obtain SQL data than I am currently using
I need to retrieve data from an external SQL Server database and view it (not store it) in my ASP.NET MVC application. The only way I can connect to the server is by using a server name, port number and access to a SQL Server stored procedure that the server owners provide. Currently the only way I know how to
SQL Join based on a column value
I want to Join different tables based on column value if [dbo].[fin_FixedAssetRegister].TransactionType = ‘IOD’ then join [dbo].[sms_IssueOrderDetail] if [dbo].[fin_FixedAssetRegister].TransactionType = ‘GRND’ then join [dbo].[sms_GoodsReceivedNoteDetail] if [dbo].[fin_FixedAssetRegister].TransactionType = ‘OBL’ then join [dbo].[sms_OpeningBalanceSMSDetail] Answer You would typically use several left joins. Your question gives very little information about the underlying structures, but the idea is: THe <???> represent the names of the
How to get output parameter results and query result from stored procedure?
I have this stored procedure which I call from C# using Entity Framework Core using a DbContext When I call the SP from code, the output parameters are empty. How to get the output parameter values in code? When I call the SP directly from SQL the output parameters are populated correctly. Answer You’re missing the OUTPUT keyword when building
Pass Minus Values for a SP
I need to pass a value for a SP by multiply it by -1. This is my query and I want pass the quantity by multiply it by -1. Is there any way to do this? Answer change your fist query to negate the sign @Quantity = -qty OR multiply it by -1
I can’t get rows have NULL on all rows for column zfeaturekey based on zplid and code type?
I work with SQL Server 2012. I have an issue I can’t get rows from table #gen when it has Null only on all rows on zfeaturekey field based on zplid and codetypeid. I need to get rows that have NULL only on all rows ON zfeaturekey, but must be same codetypeid and same zplid . Output: This is the
Procedure with cursor has missing output
I am working on an SQL Server procedure that I would like to have print the department name and students name Similar to the attached snippet The formatting should look like the attached sample snippet and there are two columns involved. students and department tables. The problem is that the results are incomplete/seems to be getting cut off below is
Conditional query with a parameter stored procedure
I’m learning SQL so I don’t know yet all the subtlety of the language, I wrote the following stored procedure (simplified here): But it doesn’t look like a natural way to do that and there is a lot of repeated code. I want to avoid something like But if it’s the only way. I don’t know the correct tag but
Define two or more conditions into a stored procedure with inner join?
First, I needed to filter the data from the tables TbTaxCompanies and tbCompany, through the variable @company_id… and works! And second I need to filter again the set of logs from the company selected previously with @company_id, but now to obtain only the latest updated taxes (only one row)… and this DOES NOT WORK! I really appreciate any help. Answer
Using arithmetic operators and/or brackets in a LIMIT clause
I have the following small subquery in query in stored procedure. But there is the syntax error: “(” is not valid at this position, expecting an identifier So, the question is: do I have a possibility to use brackets and/or arithmetic operators in LIMIT clause? Documentation says I can use local variables in LIMIT clause within stored procedure. Do I