I want to copy one table column value to another table. But both are in different databases. I did this but UPDATE dbo.Excelimp.Furniture SET dbo.Excelimp.Furniture.AssetId = dbo.Sample.FADetailsNew….
Tag: sql-server
Insert every other row to a Column
I have this Table with one row Transaction Date the first row is the checkIn and the second one is the Checkout if we organized the result by date asc. I need to pass the second row value to another …
how to take average for Varchar data type
one of my column in my table is of type varchar. which contains hexadecimal values. i need to take average for particular month . the below is my query. please help me how to change the code to achieve it. Thanks in advance Answer You can use CAST to DateTime CAST For example The filed should be a DateTime st…
Passing in parameter to where clause using IS NULL or Coalesce
I would like to pass in a parameter @CompanyID into a where clause to filter results. But sometimes this value may be null so I want all records to be returned. I have found two ways of doing this, but am not sure which one is the safest. Version 1 Version 2 I have found that the first version is
Calculate Profit Based on First-In, First-Out Pricing By Date Of Sale
How can I find the sales margin every Day via SQL, assuming they are sold in the order they were purchased? Answer Please try this solution – group by sale_date
Java JDBC – PreparedStatement executeUpdate() always returns 1
Currently I’m working on a code in java that retrieves data from XML files located in various folders and then uploads the file itself and the data retrieved to a SQL-server Database. I don’t want to upload any repeated XML file to database but since the files can have random names I’m check…
Combine multiple results into a single string in SQL Server
Is it possible to combine multiple results into a single string in SQL Server? I have the following table: How can I select the table and return the select result as below: Answer Try this:
Getting wrong output in pivot query
Attendance Table Sample Data – Student Table Sample Data – StudentSubject Table Sample Data – Subject Table Sample Data – Output – Wrong output is displaying with parameters – As 2,1,0 and NA,NA,1 should be displayed instead 2,1,1 and 2,1,1 is displaying. Couldn’t poi…
N”’ prefix is added by default while executing Stored Procedure
While executing stored procedure, I’m passing 4 arguments. After passing the arguments through GUI mode, I’m seeing that some prefixes has been added by the sql itself. So when I am removing the N”, it’s giving me an error saying Invalid column name ‘BSCCS’. What does it me…
Ignore Sunday while generating student attendance report in SQL
This code gives me the attendance report between two dates passed as a parameter. I will pass dates respective of the month selected from the C# code. But I want to skip Sundays while generating the attendance report. How can I achieve this? Answer How about changing #TempDates? This assumes that your interna…