Saturday, 26 August 2023

SQL Part-2 : How to swap two column values​​ in same table ?

 Note :  All questions are related to SQL Server.

(1) In SQL : How to swap two column values​​ ?










Ans : 
update #tempSwap set EMPNAME = DEPT, DEPT = EMPNAME;

NOTE : I used temptable for demo purpose.
Assume I have to perform operation on Employee table then query will be 

update Employee set EMPNAME = DEPT, DEPT = EMPNAME;
















Tuesday, 1 August 2023

SQL interview question Part-1

Note :  All sql related question related to SQL Server.

(1) How to get current Age based on BirthDate ?

SELECT top 5 BirthDate,  DATEDIFF ( YEAR ,BirthDate , getdate() )  as age,LoginID

  FROM [HumanResources].[Employee]






(2)  What is the output when you concate two null value using plus '+'  operator ?
        SELECT NULL +  NULL;

Ans : It will resturn single null value.












(3)  What is the output when you concate two null value using CONCATE function ?
        SELECT CONCAT (NULL, NULL)

Ans : It will resturn empty string/ blank value.





(4)  What is the output of the following code ?
        
DECLARE @TempVariable AS NVARCHAR(50)
SET @TempVariable = 'Hello World'

PRINT @TempVariable

Ans : "Hello World"


(5)  What is the output of the following code ?

DECLARE @TempVariable AS NVARCHAR(50)
SET @TempVariable = 'Hello World'

GO
PRINT @TempVariable

Ans : It will gices error. - Must declare the scalar variable "@PurchaseName".
Reason is local variable scope expires at the end of the batch once "Go" statement came.

(6)  Teacher table have 6 records, contain LastName valiues as shown in bellow.











 



What is the output of the following code ?

declare @tempLastName nvarchar(50);

select @tempLastName = LastName from [EF_Demo_DB].[dbo].Teacher;

select @tempLastName;

Ans : Jena

Explanation : Value of LastName of last record will be set in local variable @tempLastName.


(7)  What is output of following code snipet.

print null;

Ans : Blank 
Explanation : We can't print null value in sql server.



(8)  What is output of following code snipet.

Declare @localvariable nvarChar(50) =  NULL;

PRINT @localvariable + 'Tech for Boost';

Ans : Blank 
Explanation : concate with null value return blank value.



(9)  What is output of following code snipet.

declare @localvariable nvarchar(50) =  NULL;

PRINT 'Tech for Boost' + @localvariable;

Ans : Blank 
Explanation : concate with null value return blank value.

Null value containted variable when concated using '+' operator then it is first position or second position does not matter.

but concation of null value using CONCAT function gives different result. Let's see with example.


(10)  What is output of following code snipet.

declare @localvariable nvarchar(50) =  NULL;

print CONCAT('Tech for Boost', @localvariable);

-- or
print CONCAT(@localvariable, 'Tech for Boost');

Ans : Tech for Boost


(11)  Can we use GROUP BY clause without aggregate function ?

Ans : Yes, let's see with example. We have table EmployeeSalary






















Monday, 31 May 2021

C# interview question Part-1

0) What will be output of following c# code  ? (base class understanding)




(1) C# default access modifier

namespace :    public        
enum        :    public
interface :    public
class     :   private

struct           :   private

delegate         :   private  

constructor      :   private (note if no constructor is explicitly defined, 
                            a public default constructor will be automatically defined)
    
method           :   private
field :  
private
enum member      :  public
cinterface member: public
For example
namespace AccessDemo
{
    class OuterClass
    {
        void MethodA() {}
        class InnerClass {}
    }
}


is equivalent to

namespace AccessDemo
{
    internal class OuterClass
    {
        private void MethodA() {}
private class InnerClass {}
} }
(2)In Console Application, how to get input from the user ?
Ans : Using Console.ReadLine()
Console.Write("Enter input : ");
string userinput = Console.ReadLine();
Console.WriteLine("You entered '{0}'", userinput
);

output :

Enter input : test input
You entered 'test input'
'

Sunday, 10 January 2021

Angular MCQ : Angular Fundamentals : Part 5

(1) When filtering data, why should you create a copy of the data being filtered?

• To improve performance

• To improve performance

• In case you want to make edits to the data

• To maintain the order between page refreshes

• Otherwise you will lose data


(2) How do you specify where your routed components will appear in your application?

• They always appear just inside the <body> tag of your index.html.

• Use the <router-view> component.

• Use the <router-outlet> component.


(3) Once you have defined routes, how do make the router aware of them?

• Use RouterModule.forRoot or RouterModule.forChild in your Angular module.

• You don't need to make the router aware of them, declaring them as the data type "Routes" is sufficient.

• Import your routes file using a <script> tag in your index.html.

• Add the routes array to the declarations section of your module.


(4) What is the TestBed used for?

• Creating utilities for mocking services

• Integrating HTTP with Tests

• Creating mock child components

• Mimicking a Live Environment for Components


(5) What is Tree Shaking?

• An Optimization algorithm for binary searches

• A way to put multiple pieces of code together

• Automated removal of unused code


(6) When bootstrapping an Angular app, how do you specify the main Angular app module to load?

• Angular discovers the module based on the component that was bootstrapped.

• You load your module directly in your index.html file.

• You add your Angular module as a package in your SystemJs config.

• In your main SystemJs package (e.g. main.ts), you pass your app module into the platformBrowserDynamic.bootstrapModule() method,.


(7) When would you create a custom pipe?

• If you need to format an absolutely positioned node

• If you need to sort and filter your data

• If you need to have some business-specific formatting


(8) Which of the following is used as a container for components, services, directives, etc.?

• Dependency Injection

• An Angular Modules

• SystemJS


(9) Why would you use a setter on an @Input directive?

• To created a derived value on an Input value

• To validate the value of an Input

• To create a read-only input value


(10) How do you specify the html tag (e.g. <event-details>) to use for a component?

• You set the selector property in the component meta-data config.

• You set the tag property in the component meta-data config.

• You name the file that contains your component to match the tag name you want.

• You specify the tag name when declaring the component in your Angular module.


<<Angular Fundamentals part-4

Monday, 28 December 2020

Angular MCQ : Angular Fundamentals : Part 4

(1) What is the @ViewChild decorator used for?

• To add metadata for the children of a view

• The InjectionToken class To get a handle on a DOM node decorated with a ref tag(#ref_id)

• To make custom * directives


(2) An Observable represents what?

• Multiple values now

• Multiple values in the future

• Multiple values now or in the future


(3) Where should you sort and filter data?

• In your component

• In a directive

• In a filter


(3) Where should you sort and filter data?

• In your component

• In a directive

• In a filter


(4) Which decorator lets you inject a service registered with an Injection Token?

• Import

• Inject

• Input


(5) What directive helps you hide functionality you don’t want to be visible before users log in?

• ngHide

• ngShow

• ngIf

• ngAuthenticated


(6) Which decorator lets you inject a service registered with an Injection Token?

• Value comparison

• Deep value comparison

• Immutable comparison

• Mutable comparison

• Identity comparison


(7) Which of these would you use to toggle applying multiple classes to an element?

• Use a class binding

• Use a style binding

• Use ngClass


(8) What is the default token in Angular’s Dependency Injector?

• A string

• A class

• The Token class


(9) Which decorator lets you inject a service registered with an Injection Token?

• Import

• Inject

• Input


(10) Which decorator lets you inject a service registered with an Injection Token?

• Import

• Inject

• Input

 

<< Angular Fundamentals part-3      Angular Fundamentals part-5 >>

Sunday, 6 December 2020

Angular MCQ : Angular Fundamentals : Part 3

(1) Which of the following is a limitation of using template based forms?

• You can't validate the values entered into the form fields.

• You can't unit-test your validation logic.

• You can't have multiple validators on a field.


2) Which library contains the Observable class?

• Http

• RxJS

• Core


3) Which of the following is an attribute css selector?

• [selector]

• #selector

• .selector


4) What is the purpose of a mock?

• To allow you to test Http calls

• To place a boundary around tested code

• To allow you to arrange your tests easier


5) What object allows you to create your own tokens?

• The InjectionToken class

• The TransparentToken class

• The Token class


6) Which of the following would you use to display a list of elements in a component template?

• *ngRepeat

• *ngEach

• *ngFor 


7) When is the @Injectable() decorator required on a service?

• Only when it is going to be injected into components

• Only when the service also injects other services

• Only when it is going to be injected into another service


8) What's the best way to add component-specific styles to a component?

• Add the styles to a css file imported by your index.html.

• Reference an external stylesheet from inside your component template html.

• Specify the styles or styleUrls inside the component meta-data config.


9) Which of the following is true about property binding expressions?

• They cannot chain expressions together using semi-colons.

• All of these

• They cannot use the new keyword.

• Assignments using =, +=, etc are not allowed.


10) What is a limitation of multiple slot content projection?

• There is a maximum of three slots.

• The slots must be on the same horizontal.

• The slots cannot exist outside of the parent's DOM tree.



<< Angular Fundamentals part-2    Angular Fundamentals part-4 >>

Angular MCQ : Angular Fundamentals : Part 2

 1) What are decorators used for?

• To give a DOM node additional functionality

• To create sub-components

• To create smaller components


2) What is one advantage of RxJS over Promises?

• They can handle a stream of data instead of just one value.

• They are more performant.

• They are simpler.


3) When bootstrapping an Angular app, how do you specify the main, top-level app component to be used?

• You load the component directly in your index.html file.

• You add the component as a package in your SystemJs config.

• You add the component to the bootstrap array in your main app module.


4) When adding styles to a component's styles property, how do you avoid those styles affecting Html outside of your component?

• You must declare your styles inside the component's template.

• You don't need to do anything, Angular takes care of this for you by default.

• You must namespace your classes so they don't affect things outside your component.


5) What functionality do Angular 1 filters have that is missing from Pipes?

• Sorting & Filtering Data

• Working with Promises

• None of these


6) When would you use the useFactory provider method?

• When you need to parameterize the construction of a service

• When you want multiple instances of a service

• When you are using a custom service.

7) If an object could potentially be shown/hidden frequently, what's the best way to handle its visibility?

• Bind to the [hidden] property of the element.

• Use *ngSwitch to hide the element.

• Use *ngIf to hide the element.


8) Custom validators are implemented with which object?

• A Detective

• A Pipe

• A Component


9) What are the two types of Integrated tests?

• Mocked & Functional

• Deep & Shallow

• Deep & End to End


10) When validating an Angular form, how can you only show a validation message if the user has edited a form control?

• Check the control's touched property.

• Check the control's dirty property.

• Bind to the "change" event of the corresponding field and track whether the field has been changed.