Using While in Stored procedure

I am trying to import a text file to an SQL table.
I would like to check if the text file exists, if it exists, do the import, exit, if not, wait for 5 seconds, check again, and I want to loop through this process 5 times.
Here is my code, but it seems not working. Please help. Thanks

CochiseCounty:
> Here is my code, but it seems not working. Please help. Thanks
I made some changes and commented them below. Try this:
SET @TextFile = 'C:\ClaimsInquiry\Inbox\'+@ProviderNumber+'.Login.txt'

1. I presume you left out some of your code. This doesn't declare your variables or set values for @t or @i. Can you post the rest?
2. Have you tried executing your @WriteToDB string in Query Analyzer?
3. What error messages are you getting?
4. Is 'NOTHING' getting printed?

Featured Post

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied?
You can use SQL Server Initialize from Backup…

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…

Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.