Tag: tsql

How do I check the existence of a table using a variable as tablename

a) checks a table to find names of other tables that need to be created b) check if that table already exists c) if not, create it d) fill her up with new data Now, this all works fine up to the part that has to check whether the table exists: set @NewTablename = (select […]

how can I update the record in this case?

I am storing the various activities with id’s as 1,2,3,4 consecutively. If I delete the 2nd record (id 2), how can I update so that 3 becomes 2 and 4 becomes 3? Thanks in advance

Is it okay to use table look up functionalities in scalar function?

In our case we have some business logic that looks into several tables in a certain order, so that the first non null value from one table is used. While the look up is not hard, but it does take several lines of SQL code to accomplish. I have read about scalar valued functions in […]

SQL Server 2008: How to use SQL to output XML from Query?

I would like to declare a variable ‘XMLOutput’ and have it produce the contents of a table in XML format. If you could provide a really simple example I could work off of I would really appreciate it. I tried using the xmlelement() but could not get it to work.

Difference between scalar, table-valued, and aggregate functions in SQL server?

What is the difference between scalar-valued, table-valued, and aggregate functions in SQL server? And does calling them from a query need a different method, or do we call them in the same way?

column default value or including in insert script?

which is better, is there any performance difference? setting datetime column’s default value to getdate() or using getdate() with the insert t-sql script.

How do I get multiple rows when value > 1

Possible Duplicate: Select Records multiple times from table I want to have my query return (multiple) rows for the value of TABLE_B.QTY. TABLE A SALESNR ITEMNR LINENR 100 B2001 1 101 B2002 2 102 A1021 3 TABLE B LINENR COLOR QTY 1 WHITE 3 2 BLACK 1 3 BROWN 8 For instance, with the following […]

SQL: Combine Records with Same ReferenceID

I have the following records inside my table ID StudentID Semester Grade 1 1 First 100 2 1 Second 90 3 2 First 90 4 1 Third 85 I want to combine all the records of Student ID 1 in one record StudentID First Second Third 1 100 90 85 2 90 null null Any […]

sql server function that indicates if previous query returns results

Is there a function in TSql that indicates whether the previous query returned any results.

Problem with an Create Procedure or Insert Statment. Error Message: “error near @Parameter Name”

CREATE PROCEDURE dbo.InsertInboxMessage @UserID uniqueIdentifier @Message nvarchar(Max) AS INSERT INTO Messages(UsersID, Messages) VALUES(@UserID, @Message) It tells me that I have an error near @Message and that I must declare the scalar @UserID. How do I correct those errors?

MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.