Sunday, March 10, 2013

[SQL Server] UPDATE PART OF DATA

[SQL Server] UPDATE PART OF DATA


UPDATE PART OF DATA

Posted: 10 Mar 2013 12:04 PM PDT

I HAVE A TABLE WITH THREE FIELD COMCOD SIRCODE SIRDESC3305 180001 KARIM ENTERPRISE3305 180002 RAHIM ENTERPRISE3305 180003 JASON G STOREDATE TYPES COMCOD nchar(4), SIRCODE nvarchar(6) PRIMARY KEY, SERDESC nvarchar(250).I LIKE TO UPDATE ONLY SIRCODES TO START WITH 19 WHERE SIRCODE FROM THE LEFT STARTED WITH 18 THAT IS NEW TABLE WILL LOOK LIKECOMCOD SIRCODE SIRDESC3305 190001 KARIM ENTERPRISE3305 190002 RAHIM ENTERPRISE3305 190003 JASON G STORE

Filtering by StatusId

Posted: 10 Mar 2013 10:08 AM PDT

I have a Stored Procedure which returns data based on the StatusId.DECLARE @StatusId INT=2SELECT * FROM EmployeesWHERE StatusId=ISNULL(@StatusId,StatusId)If the StatusId is null,then it returns all the rows from the table Employees.And if StatusId is passed,the query returns data based on the StatusId.When @StatusId is passed as NULL,does the above query work as self-join?Also,comparing the above query with the one mentioned below,which query is more appropriate(best practice).When,I compared the query plan,both output are same.SELECT * FROM Employees eWHERE ( CASE WHEN @StatusId IS NULL THEN 1 WHEN @StatusId=e.StatusId THEN 1 ELSE 0 END)=1Thanks.

Login

Posted: 09 Mar 2013 08:21 PM PST

This is the error message I recieve whenever I login. Please help!TITLE: Connect to ServerCannot connect to "my machine name".ADDITIONAL INFORMATION:A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) (Microsoft SQL Server, Error: 2)Error Number: 2Severity: 20State: 0

Query Help

Posted: 09 Mar 2013 01:20 PM PST

[code="sql"] I want a generic query to move the "IN" state records from tableB,TableC,TableD to TableA which has studid as identity column.After moving the records to TableA delete the records with state ="IN" from tableB,TableC,TableD.Below is my sceniario but i have more nearly 15 tables which the records to be moved and deleted.Below is the Ex:TableA-------Studid Stuname State------ ------- -------1 SaM IN2 Mat INTableB-----Studid Stuname State------ ------- -------1 VIn IN2 Jon IN3 Pat NYTableC-------Studid Stuname State------ ------- -------1 Kim IN2 Jim WA3 Pat NYTableD-------Studid Stuname State------ ------- -------1 Rog IN2 Ant IN3 Put NYExpected outputTableA-------Studid Stuname State------ ------- -------1 SaM IN2 Mat IN3 VIn IN4 Jon IN5 Kim IN6 Rog IN7 Ant INTableB-----Studid Stuname State------ ------- -------3 Pat NYTableC-------Studid Stuname State------ ------- -------2 Jim WA3 Pat NYTableD-------Studid Stuname State------ ------- -------3 Put NY[/code]Thanks for you help in advance..

No comments:

Post a Comment

Search This Blog