[Solved] MS SQL Query for Opening Stock calculation

Thanks to all, i have worked out with my same query, although seed was slow. query is mentioned below:- select Item, Location,[Transaction Date],Price,Qty, Price_change , (select isnull(sum(qty),0) from #temp c where c.item=p.item and c.Location=p.Location and c.[Transaction Date] < p.[Transaction Date]) [Opening Stock] from #temp p solved MS SQL Query for Opening Stock calculation

[Solved] Update…Set…From…Where query is affecting all rows and not specific ones

Thank you all. I needed to find the common column (the ID column). UPDATE t SET t.Address=”FDAN” FROM TBTest.dbo.Site t INNER JOIN Jobs j ON t.Site_ID = j.Job_ID WHERE j.Job_No = ‘F0085′ I don’t fully understand how the aliases work. But it appears to be working fine. 13 solved Update…Set…From…Where query is affecting all rows … Read more

[Solved] SQL Query for stats on table (Help in SQL query) [closed]

Below query should do the job. Names in the ADDED_BY column seem to be the reference for aggregation in both your columns. SELECT A.ADDED_BY, A.TOTAL_RECORDS_ADDED_BY, COUNT(B.UPDATED_BY) AS TOTAL_RECORDS_UPDATED_BY FROM (SELECT ADDED_BY, COUNT(*) AS TOTAL_RECORDS_ADDED_BY FROM YOUR_TABLE GROUP BY ADDED_BY) A LEFT JOIN YOUR_TABLE B ON A.ADDED_BY = B.UPDATED_BY GROUP BY A.ADDED_BY, A.TOTAL_RECORDS_ADDED_BY; solved SQL Query … Read more

[Solved] stored procedure passing date parameter getting error

The problem is that you are building SQL in the proc, but you are not using the values in @startdate and @enddate, instead you are passing the string You need to grab the values of these variables when you build the string – something like: ALTER PROCEDURE [dbo].[ParkingDeatailsReport] @locid INTEGER, @startdate nvarchar(100), @enddate nvarchar(100) as … Read more

[Solved] String or binary data would be truncated when using it in a stored procedure

You are trying to insert 5 length character(‘dfdfg’) into your 1 length column [Access] [nvarchar](1). Increase the value of your column in Table type. CREATE TYPE [dbo].[AccessLevel] AS TABLE( [RoleId] [int] NULL, [Access] [nvarchar](25) NULL, [IsDelete] [bit] NULL ) GO solved String or binary data would be truncated when using it in a stored procedure

[Solved] multiply and SUM() MS SQL

@fia Maybe you should do your calculation elsewhere first for example on paper or in Excel to ensure you know exactly what you should get. It would also help you figure out the order of the calculation before writing it in SQL. According to the figures shown the values you’ve stated seems to be correct … Read more

[Solved] XML nodes with SQL

Please try the following solution. What we are doing here is called shredding, i.e. converting XML into rectangular/relational format. I am shooting from the hip because DDL and sample data population were not provided. The provided XML is not well-formed due to missing root element, but SQL Server allows to handle XML fragments. We are … Read more

[Solved] I am inserting excel sheet bulk data into a sql database table, now i need to split the table into multiple tables by using stored procedure [closed]

I assume that you want to dumb the data from bulk_data to myaccount table, business_setup table and business_info table. if so, Assumptions : – Column names with prefix myaccount_ belongs to myaccount table – Column names with prefix business_setup belongs to business_setup table – Column names with prefix business_info belongs to business_info table – complete … Read more