| SQL Server Interview Questions and Answers |
| Print Book Available (207 Pages) | Sample Chapters |
Download SQL Server 2008 Interview Questions and Answers Complete List
UPDATE: This article series has been updated with new interview questions and answers series.
Interview is very important event for any person. A good interview leads to good career if candidate is willing to learn. I always enjoy interview questions and answers series. This is my very humble attempt to write SQL Server 2008 interview questions and answers. SQL Server is very large subject and not everything is usually asked in interview. In interview what matters the most is conceptual knowledge and learning attitude.
I have listed all the series in this post so that it can be easily downloaded and used. All the questions are collected and listed in one PDF which is here to download. If you have any question or if you want to add to any of the question please send me mail or write a comment.
SQL SERVER – 2008 – Interview Questions and Answers – Part 1
SQL SERVER – 2008 – Interview Questions and Answers – Part 2
SQL SERVER – 2008 – Interview Questions and Answers – Part 3
SQL SERVER – 2008 – Interview Questions and Answers – Part 4
SQL SERVER – 2008 – Interview Questions and Answers – Part 5
SQL SERVER – 2008 – Interview Questions and Answers – Part 6
SQL SERVER – 2008 – Interview Questions and Answers – Part 7
SQL SERVER – 2008 – Interview Questions and Answers – Part 8
Download SQL Server 2008 Interview Questions and Answers Complete List
Reference : Pinal Dave (
http://blog.SQLAuthority.com
)
Well done, it must took you a good while to write these questions for the greater good
I was wondering when the interview articles will finish, so I can print them double-sided
now with the PDF, problem solved.
Many thanks Pinal, from Canada
Jerry Hung,
You are welcome.
Regards,
Pinal Dave
Hi Pinal,
I am in delima..
[removed privacy related information]
If is store this string in sql2008 then can i make regex in sql query where i can extract each line independently. i.e. each line is equal to column value..
how to Create a procedure or method followed by the ID of the user with a statement of income and output and how to call to find out what product profits after a specific date
Where do I download the questions and answers? When I click the link it just open up new window for ever.
Hi Pinal ,
i want to know how to Insert Excel file in binary format in perticular one Collum of sql Table.
Use varbinary(max) column and openrowset
INSERT INTO your_table(FileName, Document)
SELECT 'Text1.txt' AS FileName,
* FROM OPENROWSET(BULK N'C:\your_excel.xls', SINGLE_BLOB) AS Document
But I would say it is better you store the file path to the table and keep the file in Server’s directory
hi…. madhivanan
i want to create query to insert a document like our CV or Resume when we retrieve it
INSERT INTO your_table(FileName, Document)
SELECT ‘Text1.txt’ AS FileName,
* FROM OPENROWSET(BULK N’C:\your_excel.xls’, SINGLE_BLOB) AS Document
send me query to retrive word document through query.
when i fire a query
i hope u may respond me ASAP….
byeee
Regards
sanju
You need to use a front end application to open the document
I have to design a script which would go thru the DB and extract a flat file of each pertinent table’s data(1 file/table).I have used DTS to export data from databases.I have never written a script for extraction.Could you please guide me on this and help me in getting started on how to write a script with a small example.Could you also please help me on how to run the script against the database so that it could generate a data file
Do u usually reply to their email or post solutions here?
Thanks
Shveta
Hi Pinal,
Greatest work..Thanks a ton..You have made concepts clear to me..
Pramila
hi Pinal,
thanks a lot,……i think no book will give as much wealthy knowledge as your website gives…..this is the real place to learn a lot and that too your examples are amazing…..easy to understand and learn……..thanks a lot.
Dear
pinal
I am looking forward to change . so for that i need sql server 2005 question and answer
regards
karan
My SQL statements are:
CREATE TABLE doc_exe ( column_a INT CONSTRAINT column_a_un UNIQUE)
GO
ALTER TABLE doc_exe
alter column column_a int identity(1,1)
I get the error:
Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword ‘identity’.
Please explain or correct the sytax.
Thanx
It is not possible to alter the column to have identity property
One way is to drop the column and recreate it with identity property
Greatest work..Thanks
Hi Pinal,
I have table structure with data like below. all columns are key columns.
Col1 col2 col4
a1 c 1
b1 a 1
c1 b 1
d2 b 2
b2 c 2
c2 a 2
a2 d 2
b3 a 3
a3 d 3
But I want a query to get first record group by col4. the resultset should be
Col1 col2 col4
a1 c 1
d2 b 2
b3 a 3
Please guide me to get a query.
Thanks,
select col1,col2,col4 from
(
select *,row_number() over(partition by col4 order by col4) as sno from your_table
) as t
where sno=1
select max(col1),max(col2),col4 from a group by col4
hom many time takes to download sql server 2008 ?
Hi Pinal,
So nice of you. You are doing a very big help and guidance to people like me.
God bless You and your family.
Hello Sir,
The information there on this blog is very useful & helpful thanks for providing such informative infromation.
Sir i have a query in ms-sql server2000
can we convert numeric(18,0) to identity(1,1) which will be primary key ,
since this ID numeric(18,0) is a foreign key in another table so i wanted that this key should be as primary auto incrementing key
whereas i am also unable to do insert into statement for the same
error ocuuring is as : Cannot insert explicit value for identity column in table
Can you please help me out.
Smita,
You have to drop that column and recreate it with IDENTITY property and also we can not insert any value for Identity column
hi
i want to store a image in sql server 2005 by usging Sql command
plz guide me
It is better to store the image url in the table and physical images in the directory.
Hi Dave,
I’m very new to SQL server. Could you please guide with any training materials. Thank you
Pingback: SQL SERVER - Interesting Interview Questions Journey to SQL Authority with Pinal Dave
Dear Pinal Dave
Really your are doing marvels Job I would like to appreciate your effort and Pray from God you always maintain this effort for deprived person like me.
Regard
Muhammad Junaid Babar
Pingback: SQL SERVER - Interesting Interview Questions - Part 2 - Puzzle Journey to SQL Authority with Pinal Dave
Gr8 job dude..!
Girish Advani
Gujarat
Wonderful Work!
Pingback: SQL SERVER - Interesting Interview Questions - Revisited Journey to SQL Authority with Pinal Dave
Pingback: SQL SERVER - Top Five Articles of Year 2008 Journey to SQL Authority with Pinal Dave
its helping me more to walk in interview
thanks for such a ……
like qus
Hi Pinal,
In your pdf, you have mentioned that “Update Statistics will updates indexes on tables” which is incorrect. Update statisitics will only update stats. For updating indexes you need to rebuild indexes.
Also you have mentioned that select rows from sysindexes is a accurate way of getting rowcount which is also incorrect. If statistics is outdated then this would not give you accurate result.
AD
To get correct rowcount, you need to run
DBCC Updateusage
But I think from version 2005 onwards this is taking care automatically
Pingback: SQL Server Interview Questions and Answers - Introduction Journey to SQL Authority with Pinal Dave
Pingback: SQL Server Interview Questions and Answers - Part 1 Journey to SQL Authority with Pinal Dave
Pingback: SQL Server Interview Questions and Answers - Part 2 Journey to SQL Authority with Pinal Dave
Pingback: SQL Server Interview Questions and Answers - Part 3 Journey to SQL Authority with Pinal Dave
Hi Dave,
I’m very new to SQL server. I dont know anything about SQL.I am in SQL administrator destination.Could you please guide with any training materials. Thank you
Regards,
Krishna
If you are more concerned about wring t-sql, first lean sql. Search for “Learn SQL” in Google/Bing
Pingback: SQL SERVER - 2008 - Interview Questions and Answers - Part 4 Journey to SQL Authority with Pinal Dave
Pingback: SQL SERVER - 2008 - Interview Questions and Answers - Part 3 Journey to SQL Authority with Pinal Dave
Pingback: SQL SERVER - 2008 - Interview Questions and Answers - Part 7 Journey to SQL Authority with Pinal Dave
HI Dave,
I want to make a good career in DBA so will you please tell me what will I do to get good career in MS SQL
Could you please guide me what I do for getting more knowledge in SQL
Please give me advice.
hello sir,
your articles are very nice and all
the students of sql server are enjoyed a lot
Thanks!!!
Hello Mr Dave
Im Sudha..i found ur site today when i was searching for sql server material….My doubt is i want to take sql server 2008 certification..could you plz tell me which is best i mean sql server 2005 r 2008 i didnt take any exam so which is best i mean
MCTS: Microsoft SQL Server 2005
• MCTS: Microsoft SQL Server 2005 Business Intelligence
• MCTS: Microsoft SQL Server 2008, Business Intelligence Development and Maintenance
• MCTS: Microsoft SQL Server 2008, Database Development
• MCTS: Microsoft SQL Server 2008, Implementation and Maintenance
could u plz tell which one is best.
Thanks
Sudha
I am getting this kind of error. during the installation i didnt give any login name and password . so what to enter here as login name i dont know.i tried some of them ur solution still give me same error. My Os is window vista and if i try to see service from computer management does not give me service of sql server.
please help me out.
TITLE: Connect to Server
——————————
Cannot connect to 76.194.236.194.
——————————
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: 3)
Hi,
I was going thru your interview question collection. In your question “What is difference between DELETE & TRUNCATE commands?” you have mentioned that “TRUNCATE cannot be rolled back”. But I believe this in NOT true and we can rollback a truncate statement.
For example:
Create table #test (I int)
Insert into #test values (1)
Begin tran
Truncate table #test
Rollback
Select * from #test
Drop table #test
The above code snippet returns a value 1. Could you please tell me how this is possible?
Regards,
Rakesh
The Truncate command inside a trasaction can be rolled back as it is clear from the example you have given
Thank you for the Q&A pdf. This is really precise and very helpful.
i want to build my career in database.
could u tell me for which certification should i go?
i mean ORACLE or SQL2008.
someone told me that sqlserver2008 will be the best. i m getting confused. pls suggest me.
I m pursuing MCA final year from regular.
thanks
paramjeet singh
I want to learn SQL 2008 and installed, but no front end, like query analyzer, or query developer installed, am I missing something, I tried installing the SQL Management Studio_x86_ENU studio but none looks like installed on my system, my operating system is Windows Vista Ultimate.
Please, guide me, your help is appreciated. – Thank you.
Best regards
udmalla
While installing version 2008 did you get any errors?
What did you mean by ” none looks like installed on my system”?
I have install sql server 2005 in vista ultmate without any problem but not any database is install tell me how can I intall the database and I am not able to write any sql query.
@Dinesh,
If you want sample databases, on which you can learn some Good SQL. Then try installing sample databases.
Here is a step by step pictorial explanation on how to install sample databases.
http://blog.sqlauthority.com/2008/08/10/sql-server-2008-download-and-install-samples-database-adventureworks-2005-detail-tutorial/
~ IM.
Dear @param,
It has been observed that microsoft copies the idea from other softwares or products and make their own one.
However, I’d recommend that If you are really interested in database then you should go for Oracle.
There’s so many reasons but I’ll not going in depth.
Thanks!
Pingback: SQL SERVER – 2008 – Interview Questions and Answers – Part 5 Journey to SQL Authority with Pinal Dave
Really awesome help.
Hey!
Brilliant blog!
Thanks for the pdf!
Regards,
Shravan.
Thanks so much for the Questions and Answers
Thanks again!!!!
Anks
Pinal sir.. great work …
Hi Pinal,
I want to get certification for SQL Server 2005/2008. Can you please provide me the reading material for the same.
Thanks,
Hi Dave
An excellent work and very useful material.
thanks for providing
& Congrats on having baby
Hi Pinal ,
I have written the query in MDX Query Editor in SOL Server 2008 Successfully,
But the problem is when we implement the same query in Cube(as expression in calculated measure) its not working in SSAS 2008
The Error is:- Select statement is not correct in MDX Expression
nice job! your Q&A is most appreciated
Thanks
Hi Pinal,
I have a query for you, Can we write a select query to select only nth row from a table without using where clause?
This question was asked to me in one of my interview.
Regards,
Ashwin Shende
Yes we can get 200th row from the table Virus
in following way.
I am ordering on column nam virusname by descending order and then getting first row.
select top 1 * from (
select top 200 * from virus
order by virusname
desc
) as temp
just try it..
Why is it “without using where clause”?
Refer this to know more methods
http://beyondrelational.com/blogs/madhivanan/archive/2007/08/27/find-nth-maximum-value.aspx
@Ashwin
Without a WHERE clause? That’s an interesting question. That answer is yes, though it is inefficient. If the only the second record is wanted:
DECLARE @A TABLE (A INT);
INSERT INTO @A SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3;
SELECT TOP(1)
A
FROM
(
SELECT TOP(2)
A
FROM
@A
ORDER BY
A
) A
ORDER BY
A DESC;
Thanks a Lot :-)
I’m very new to SQL server. Could you please guide with any training materials. Thank you
Pingback: SQLAuthority News – 1200th Post – An Important Milestone Journey to SQL Authority with Pinal Dave
…Ek Dum Jhakaas….Really Good Job….Thanks
Vande Matram…
Regards
Mitesh Neema
INDIA
Please, i want to knew what is sql jobs?
Read about Jobs in SQL Server help file
It is a good start to know the informations
Pinal,
Good job. This helped me a lot.
Regrds,
Sreeni
hi
i need sqlserver question and answer for middle stage
can you send ssis and DTS packages diff.
thanks
vinay
Many thanks
Thank You Pinal …
Sql 2008 Qns are really helpful
Dave, i take issue with this statement: “Identity/GUID columns do not need to be indexed.” I will agree the statement is correct IF YOU NEVER USE THE COLUMN (but then i would submit the column exists for no valid reason, and that’s a different discussion).
Often, the identity column is used as a surrogate primary key (and very often because the table designer was too lazy to figure out what data element(s) uniquely identify the row — again, a different discussion).
If the identity column is used as a primary key in this table, and then as a foreign key in other tables, the identity column must ABSOLUTELY be indexed (unless the table is so small that it is always in memory… or unless you enjoy table scans).
there is no automatic creation of an index on an identity column, and there is no automatic clustering of data based upon that identity column.
hello,
how r u, i have a request based on sql server. how to insert bulk records into the data base? i know how to insert one record at a time
You can have data in a text and use bulk insert to copy data to a table. Refer this post for more informations
http://beyondrelational.com/blogs/madhivanan/archive/2010/03/17/bulk-insert-to-table-with-specific-columns.aspx
@Swetha,
Bulk Insert inserts huge number of records from another source (outside SQL Server) into SQL Server.
Why you want to use Bulk Insert when you want to insert one record at a time.
What is the your requirement why you want to insert one record at a time, Of-course there are many ways of doing it
But why use Bulk Insert when you do not want to take advantage of its features ?
Please provide us more details so that we can suggest you most optimal solution.
~ IM.
Hi, Pinal
We are considering to migrate from SQL Server 2000 to 2008. I think the version 2008 should be backward compatible.
Would like to check is there any changes like those command being used in 2000 could not be used (not supported) in the version 2008? as I overheard in the past where some of the version 2000 cmd no longer applicable in version 2008.
I need your advice,pls.
THanks in advance.
Hello Avalyn,
You can identify the possible issues using Microsoft’s SQL Server 2008 Upgrade Advisor tool.
Regards,
Pinal Dave
This is very good and useful. if you give with an example mean it is very useful.
Thanks a lot, Pinal ;)
Very nice, Pinal.
I noticed that most of the questions are
‘What is……?’
What about more deep knowledge questions
like ‘Why … ?’
And maybe it worth to divide the questions that
relevant to Applicative(development) DBAs and for Production(Infrastructure) DBAs?
For example:
http://madebysql.blogspot.com/2010/03/applicative-dba-interview-questions.html
Thanks.
sql connection related problem
Hi Pinal,
I have learnt lot of thing from your site.
I want to know more about performance tuning in sql server 2005. What is the possible questions on performance tuning.
Please let me know if it is possible.
syed
Dear
pinal
I am looking forward to change . so for that i need sql server 2005 question and answer
regards
syed
Hi Dave,
I am fresher, I want to know the usage of
SET ANSI_PADDING ON/OFF
with clear explanation and practical example
Many thanks & regards in advance,
Naveen
Ttype SET ANSI_PADDING at SQL Server help file
It has explanation with example codes
Thank you sir.
Hi Panal,
Great going, We are benefiting a lot form your site.
Thanks,
SK
Actually, I am .NET developer. But most of the compnies requires that we have strong knowledge of SQL too. You article helped a lot.
One thing I want to share with you. Some of my friends gave interview in Patni Computers, Gandhinagar for .NET. They were asking questions about SQL only (for .NET positions). They were asking question of Database administrator level (Database mirroring, SSIS, DTS packages etc.) Do you think, all .NET developer should have DB Admin level of SQL knowledge?
I need some help in such a way that, what is the difference between
“Casting” And “Convert.ToXXX()” In SQL Server.
Refer this post. It describes the difference between the two
http://beyondrelational.com/blogs/madhivanan/archive/2010/07/22/cast-vs-convert.aspx
I am calling sp_oaCreate to add DTS package in SQL Server 2008 64 bit environment.
I am getting an error “Class not registered”. When I googled I found that MS do not support sp_oa*** system stored procedures in SQL Server 2008 64 bit environment.
My requirement is to execute the DTS package from Stored proc and get the data. I am using sp_oa*** sp to do this.
Now I cannot use sp_oa*** in SQL Server 2008 64bit envi. Is there any other solution?
Hello Pinal
please check if you can help about the below topic
This is just an interview question i got from one of interviewer. for which I did not knew answer.
Any insight on this welcome..
If we have dimension tables loaded and used surrogate keys for processing. Now what happens is the we loaded fact table too. What happens if the dimension tables gets corrupted and we do not have any backup of the dimension tables. So will the fact table still funstional and will give us correct results. Is there any we can get out dimension tables back from the fact table (keep in mind there is surrogate key used).
Do we need to rebuild the fact table by rebuilding the dimension table. Will it cost much time reuilding fact table. Is there any approach besides this.
Thank you, Pinal! Much appreciated.
Hi Pinal,
Can you please help me with a script to automate the backup process and archive the old backups which also includes the transaction log backups and differential.
Thank you
Here is the one for automating the backup of the database
http://beyondrelational.com/blogs/madhivanan/archive/2010/05/10/backup-all-databases.aspx
Hi Pinal,
I have learnt lot of thing from your site.
I want to know more about performance tuning in sql server 2005. What is the possible questions on performance tuning.
You can identify the possible issues using Microsoft’s SQL Server 2008 Upgrade Advisor tool.
Please let me know if it is possible
Hi Pinal Dave
I downloaded your “SQL Server 2008 Interview Questions and Answers”. It’s fanatastic.
Many Thanks.
Regards,
Ganesan.
Hi there,
I created a publication using sql 2008 serve. the publication was deleted. I want to know if there is a way to discover the computer that connected to the server and deleted this publication. Any Help?
In the following table, RESPONSES counts how many times SEGMENT has responded on CHECKED date.
CREATE TABLE #TEST (ID INT, SEGMENT CHAR(1),RESPONSES INT,CHECKED SMALLDATETIME)
INSERT INTO #TEST VALUES (1,’A',0,’2009-05-01′)
INSERT INTO #TEST VALUES (2,’B',1,’2009-05-01′)
INSERT INTO #TEST VALUES (3,’C',0,’2009-05-01′)
INSERT INTO #TEST VALUES (4,’A',0,’2009-05-02′)
INSERT INTO #TEST VALUES (5,’B',2,’2009-05-02′)
INSERT INTO #TEST VALUES (6,’C',1,’2009-05-02′)
INSERT INTO #TEST VALUES (7,’A',1,’2009-05-03′)
INSERT INTO #TEST VALUES (8,’B',0,’2009-05-03′)
INSERT INTO #TEST VALUES (9,’C',2,’2009-05-03′)
Write a query to summarise total RESPONSES for each SEGMENT and each CHECKED date, shown in following format:
CHECKED A B C
2009-05-01 0 1 0
2009-05-02 0 2 1
2009-05-03 1 0 2
Do NOT hard-code segment names (i.e. “A”, “B”, “C”) into your solution, so the solution remains functional if more segments are added (e.g. “D”) or segments are renamed (e.g. “A” “X”).
Refer this dynamic PIVOT post which does what you want
http://beyondrelational.com/blogs/madhivanan/archive/2008/08/27/dynamic-pivot-in-sql-server-2005.aspx
I want to get certification for SQL Server 2005/2008. Can you please provide me the reading material for the same.
Thanks.
Thanks Pinal Dave , You are doing Very Good work for everyone.
its grt
Hi Pinal,
I got question in my interview what he ask me like if he want to fetch 1 million records what type of query will need to write?
Please give me this answer I am confused what should I answer for this question I asked other friends also but they don’t give me the write answer and I have hope I get it from you.
Regards
Khan
truncate can be rollback,but delete can’nt rolback.
This is absolutely wrong. Where did you read this?
Hi Rakhi,
From where did you get this knowledge that “truncate can be rollbacked, but delete can’t”, so untrue?
I’ve also heard people speaking contrary that “delete can be rollbacked, but truncate cannot”.
But the real thing is that both can be rollbacked, when applied inside the transaction.
~Manoj
Adding more to my comments above:-
“Without or Outside Transactions”, When DELETE/TRUNCATE is applied outside the transaction the changes are committed as soon as you execute sql statements. Thus nor DELETE neither TRUNCATE can be rollbacked. Thus in order to retrieve DELETED/TRUNCATED records you have to restore the last backup and run the transaction logs until the time DELETE/TRUNCATION happened.
Friends
in case of outside the transaction ..you can only rollback delete not truncate.
thnx
@Ankur, have to tested this at your end or are you just spreading word of mouth.
Can you show us how can do do that? Like an example.
Thanks you so… much . I’m appreciating your work .
Keep doing
Hi Sir
please send me interview question (frequently asked).
Hi Sir
Can you send me the sql server 2008 s/w link to my mail-id
please…
Hi Pinal,
Is there any levels for Recursive CTE like stored procedures?
How many levels we can go?
Thanks,
Anand
It can go to any level but you need to specify the max recursion option to 0
Hi Pinal,
Thanks for putting this together. However I’m having a problem printing the PDF.
It’s security protected (DRM) preventing it from being copied or printed.
Thanks
Adam,
did you ever get a reply?
Thanks a Million
It’s Really Gr8 Job
Good job dude.
Questions are very good but answer does not sound good.
Any how gr8 work.
Hi Sir,
I have done mcom i was working as mis reporting in excel , company got relocated i was in search of job someone suggested me do course in oracle DBA …I finished my course can u suggest me how shld i study… and prepare for interview and pls send me interview question to my mail id….pls i am physically challenge girl i am struggle to find job…
Thanks for this post; it’s really helpful.
HELLO SIR,
HOW TO MAKE UNION OF “2 IF CONDITION” QUERIES?
FOR EXAMPLE:
IF(J=J)
BEGIN
SELECT ID,* FROM TABLE1
END
UNION
IF(I=I)
BEGIN
SELECT ID,* FROM TABLE2
END
WITH GROUPBY ID
Put the IF condition in the WHERE clause of each query
sir,
What is difrrences in sql server backup and windows backup.
hi., some one plz suggest me a project on Oracle 10g (for B.tech final year project)
Great work, good basic set of questions. It is great that I can download them. I can see preventing the changing of the document, but preventing the printing is a little overboard. if I can download, why cant I print?
I use your questions a a reference point to what topics I really want to touch on during an interview. I do not always have a computer nearby.
Pinal you are king of SQL and SQL server!
amazing website, thanks for sharing your knowledge with us
cheers
C
Hi,
In Change Data Capture What is Diffrence Between $start_lsn And $eqval
Hi
After creating the cdc (table_CT) table that is genrated in system table cant Be Modified Means It Dosnt have Design option in sql server 2008
Can Anybody Give Me Solution For This
Hi,
I am using SQL SERVER 2008 R2. In that i was created the job for taking the back up. It was working from the day of it is created. But from the last week it was not executed and also it shows error” Execution Failed.,See the Maintanence Plan and SQL Server Agent Job History logs for details”
Please let me know why it happens? What is the solution to resolve this?
See if the SQL Server agent is running. Also check if the password got changed for the account that runs a job
Is it possible to add an application develped in VB.net & SQLServer2008 to system startup..???
why we use indexes in sql server 2008. please let me know in detail.
Hi pinal,
This is good for fresh people who just learn sql server and want to job as developer.
But pinal , I am looking for some technical interview question with answer and some technical example as well.
Because in some job people take interview with situation , action and result.
I am looking that kind of interview question and answer.
Hi Pinal,
I’m having a very hard time in findig a way to enter my @FromDate and @ToDate into my procedure…can you please help and show me where do i need to enter these. Thank you so much in advance
CREATE Procedure dbo.UHS_Rapidresponsedoc_RS_PR
(@JobId int
)
as
Begin
Set NoCount on
Declare @FromDate DATETIME
Declare @ToDate DATETIME
Declare @SubmittedReportGUID HVCIDdt
DECLARE @InputParamTable TABLE
(
InternalValueGUID VARCHAR(30),
ValueFrom VARCHAR(255),
Name VARCHAR(30)
)
SET @SubmittedReportGUID = (SELECT
SubmittedReportGUID
FROM HVCRequestedReport
WHERE JobID = @JobId)
INSERT INTO @InputParamTable
SELECT InternalValueGUID,
ValueFrom,
Name
FROM HVCSubmittedParameter
WHERE SubmittedReportGUID = @SubmittedReportGUID
–Select * from @InputParamTable
— Get the Report Date Intervals
SELECT @FromDate =
CASE
WHEN LEFT(RP.ValueFrom,1) = ‘t’ AND LEN(RP.ValueFrom) = 1 THEN
CONVERT(varchar(11), GetDate())
WHEN LEFT(RP.ValueFrom,1) = ‘t’ AND PATINDEX(‘%+%’,RP.ValueFrom) 0 THEN
DATEAdd(dd,convert(numeric,LTRIM(RIGHT(RP.ValueFrom,LEN(RP.ValueFrom)-PATINDEX(‘%+%’,RP.ValueFrom)))),CONVERT(datetime,CONVERT(varchar(11),GetDate())))
WHEN LEFT(RP.ValueFrom,1) = ‘t’ AND PATINDEX(‘%-%’,RP.ValueFrom) 0 THEN
DateAdd(dd,-convert(numeric,(LTRIM(RIGHT(RP.ValueFrom, LEN(RP.ValueFrom)-PATINDEX(‘%-%’,RP.ValueFrom))))),CONVERT(datetime,CONVERT(varchar(11),GetDate())))
ELSE CONVERT(datetime,RP.ValueFrom)
END
from @InputParamTable RP
where RP.Name = ‘HVCFromDate’
SET @FromDate = CAST((SELECT @FromDate
) + ‘ ‘ + (SELECT
ISNULL(ValueFROM, ’00:00′)
FROM @InputParamTable
WHERE Name = ‘HVCFROMTime’) AS DATETIME)
SELECT @ToDate =
CASE
WHEN LEFT(RP.ValueFrom,1) = ‘t’ AND LEN(RP.ValueFrom) = 1 THEN
CONVERT(varchar(11), GetDate())
WHEN LEFT(RP.ValueFrom,1) = ‘t’ AND PATINDEX(‘%+%’,RP.ValueFrom) 0 THEN
DateAdd(dd,convert(numeric,LTRIM(RIGHT(RP.ValueFrom,LEN(RP.ValueFrom)-PATINDEX(‘%+%’,RP.ValueFrom)))),CONVERT(datetime,CONVERT(varchar(11),GetDate())))
WHEN LEFT(RP.ValueFrom,1) = ‘t’ AND PATINDEX(‘%-%’,RP.ValueFrom) 0 THEN
DateAdd(dd,-convert(numeric,(LTRIM(RIGHT(RP.ValueFrom, LEN(RP.ValueFrom)-PATINDEX(‘%-%’,RP.ValueFrom))))),CONVERT(datetime,CONVERT(varchar(11),GetDate())))
ELSE CONVERT(datetime,RP.ValueFrom)
END
from @InputParamTable RP
where RP.Name = ‘HVCToDate’
SET @ToDate = CAST((SELECT @ToDate
) + ‘ ‘ + (SELECT
ValueFROM
FROM @InputParamTable
WHERE Name = ‘HVCToTime’) AS DATETIME)
select cv.providerdisplayname
,u.displayname as authoredprovider
,cv.clientdisplayname
,cv.idcode
,cv.visitidcode
,cd.createdwhen
,cd.documentname
,cd.AuthoredDtm
,cd.ArrivalDtm
,cp.DisplayName
from cv3clientdocument cd
inner join cv3clientvisit cv
on cd.clientvisitguid = cv.guid
inner join cv3user u
on cd.authoredproviderguid = u.guid
inner join cv3careprovider cp
on cv.providerdisplayname = cp.displayname
where cd.documentname not like ‘%Phone%’
and cv.clientdisplayname not like ‘TEST%’
and cd.documentname like ‘%Rapid%’
and dateadd(dd, datediff(dd, 0, cd.ArrivalDtm ), 0) <= dateadd(dd, datediff(dd, 0, GETDATE()), 0)
and cd.ArrivalDtm between @FromDate and @ToDate
order by providerdisplayname,u.displayname,clientdisplayname
Set NoCount off
end
sir,
please tell me what are the main differences between ms access and sqlserver . when to use both different application?
sir,
please tell me how to count the number of column in a table?
SELECT COUNT(SC.name) AS [Num of Columns]
FROM sys.objects SO
INNER JOIN sys.columns SC ON SC.object_id=SO.object_id
WHERE type = ‘U’ AND SO.name = ‘Your Table_Name’
sir plz solve my problem by query ,i.e. we need a query which select data from 2 tables -
1- male(table1)
2-female(table2)
we need to get data which give alternative male and females value on by one.
plz reply me.
It is ggod to have and prepare . Thank you in advance.
hello sir ,
i have this problem while attaching the northwind test database .as show
sir how i can slow this :
thank you
Regards sanaullah
TITLE: Microsoft SQL Server Management Studio
——————————
Attach database failed for Server ‘HP-PC\SQLEXPRESS’. (Microsoft.SqlServer.Smo)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=10.50.1447.4+((KJ_RTM).100213-0103+)&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=Attach+database+Server&LinkId=20476
——————————
ADDITIONAL INFORMATION:
An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)
——————————
Unable to open the physical file “C:\SQL Server 2000 Sample Databases\northwnd.mdf”. Operating system error 5: “5(Access is denied.)”. (Microsoft SQL Server, Error: 5120)
very thanks man,
is there a way i can print this book.
What special Oracle feature allows you to specify how the cost based system treats a SQL statement
hey,can u tell me that,we are using oldb namespace in case oracle connectivity,and this also possible in case of sql2008 also,so what is needs to implement using.system,data,sqlclient